Skip to content

Fix: Raise GvmError when the remote closed the connection on send - #1402

Merged
greenbonebot merged 3 commits into
greenbone:mainfrom
m1kados:fix-send-remote-closed
Nov 30, 2026
Merged

greenbonebot merged 3 commits into
greenbone:mainfrom
m1kados:fix-send-remote-closed

Conversation

@m1kados

@m1kados m1kados commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

What

AbstractGvmConnection.send() now converts a ConnectionError (BrokenPipeError, ConnectionResetError, ConnectionAbortedError) raised by the socket into a GvmError("Remote closed the connection. Error was ..."). read() does the same if the socket raises while receiving. The original exception is kept as __cause__.

Why

When the remote server has closed the connection, for example gvmd after an error response, the next send() raised a raw BrokenPipeError/IOError from the socket, while read() on a closed connection already raises a GvmError. Callers had to catch IOError and check errno.EPIPE themselves to find out that they need to re-connect. With this change a closed connection is reported consistently as GvmError for both directions.

This affects UnixSocketConnection and TLSConnection, which share the implementation. SSHConnection has its own send() and is unchanged. Other socket errors such as timeouts are not wrapped.

Closes #11

How it was tested

  • New unit tests in tests/connections/test_gvm_connection.py for sending on a closed connection, a reset while reading, sending on an unconnected socket, and for timeouts staying unwrapped.
  • Reproduced manually with a real socket pair: sending to a closed peer now raises GvmError instead of ConnectionAbortedError.
  • ruff check and ruff format --check pass.
  • I developed this on Windows, where a number of connection tests (Unix socket, SSH known_hosts) already fail on main, so I rely on CI for the full test suite and mypy.

🤖 Generated with Claude Code

Sending a command over a connection that has been closed by the remote
server, for example by gvmd after an error response, raised a raw
BrokenPipeError/ConnectionResetError from the socket. Reading from a
closed connection already results in a GvmError.

Convert connection errors raised while sending or reading into a
GvmError too, so callers can handle a closed connection consistently
and re-connect. The original exception is kept as the cause.

Closes greenbone#11

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@m1kados
m1kados requested a review from a team as a code owner November 10, 2026 01:56
@greenbonebot
greenbonebot enabled auto-merge (rebase) November 10, 2026 01:56
@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Conventional Commits Report

Type Number
Bug Fixes 2

🚀 Conventional commits found.

Comment thread gvm/connections/_connection.py Resolved
TLS sockets raise ssl.SSLEOFError or ssl.SSLZeroReturnError if the
remote server has closed the connection. Both aren't ConnectionErrors
and therefore were not converted into a GvmError for a TLSConnection.

Handle them the same way as connection errors when sending and
reading. Other SSL errors are still passed through unchanged.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
auto-merge was automatically disabled November 28, 2026 14:28

Head branch was pushed to by a user without write access

@greenbonebot
greenbonebot enabled auto-merge (rebase) November 28, 2026 14:28
@greenbonebot
greenbonebot merged commit 7348b80 into greenbone:main Nov 30, 2026
25 checks passed
@codecov

codecov Bot commented Nov 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.53%. Comparing base (f95ecc1) to head (1265ca9).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1402   +/-   ##
=======================================
  Coverage   98.53%   98.53%           
=======================================
  Files         107      107           
  Lines        7091     7099    +8     
  Branches     1310     1310           
=======================================
+ Hits         6987     6995    +8     
  Misses         74       74           
  Partials       30       30           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UnixSocketConnection handle remote close

3 participants