Skip to content

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

Open
m1kados wants to merge 1 commit into
greenbone:mainfrom
m1kados:fix-send-remote-closed
Open

m1kados wants to merge 1 commit into
greenbone:mainfrom
m1kados:fix-send-remote-closed

Conversation

@m1kados

@m1kados m1kados commented Nov 10, 2026

Copy link
Copy Markdown

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

Copy link
Copy Markdown

Conventional Commits Report

Type Number
Bug Fixes 1

🚀 Conventional commits found.

This branch has not been deployed

No deployments
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

1 participant