Skip to content

io: close the session on hang-up results - #1360

Open
ejohnstown wants to merge 2 commits into
wolfSSL:masterfrom
ejohnstown:io-callback-contract
Open

ejohnstown wants to merge 2 commits into
wolfSSL:masterfrom
ejohnstown:io-callback-contract

Conversation

@ejohnstown

Copy link
Copy Markdown
Contributor

The I/O layer marks the session closed for two callback results it
used to treat as something else.

  • GetInputData() fails with WS_SOCKET_ERROR_E when the recv callback
    returns 0, instead of spinning DoReceive()
  • wsEmbedSend() maps ECONNABORTED to WS_CBIO_ERR_CONN_CLOSE, matching
    wsEmbedRecv()

Issue: F-14397, F-13903

GetInputData() now fails with WS_SOCKET_ERROR_E and marks the session
closed when the recv callback returns 0, as GetInputLine() already
does. A custom callback reporting an orderly shutdown no longer spins
DoReceive() forever.

- tests: DoReceive with a callback that always returns 0

Issue: F-14397
Copilot AI balanced review requested due to automatic review settings November 2, 2026 18:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new test can fail under contention builds due to injected would-block results and under lwIP builds because it may intercept the wrong send backend.

2 open issues
What changed in this PR

This PR updates wolfSSH’s I/O handling to recognize peer hang-ups, preventing repeated receive attempts and marking affected sessions closed.

Changes:

  • Treat a zero receive-callback result in GetInputData() as a fatal socket error.
  • Map send-side ECONNABORTED to a closed connection, matching receive-side handling.
  • Add regression tests for both cases and their session-state effects.
File Description
tests/​unit.c Adds zero-receive and aborted-send regression tests.
src/​io.c Maps send-side ECONNABORTED to connection closure.
src/​internal.c Stops packet reception and marks the session closed on zero-byte reads.

Review effort: Balanced

Comment thread tests/unit.c Resolved
Comment thread tests/unit.c Resolved
@ejohnstown
ejohnstown force-pushed the io-callback-contract branch from e1bd68d to 716bff8 Compare November 2, 2026 20:09
wsEmbedSend() returns WS_CBIO_ERR_CONN_CLOSE for SOCKET_ECONNABORTED,
matching wsEmbedRecv(), so an aborted connection during a send sets
isClosed instead of being reported as a general error.

- unit: a send failing with ECONNABORTED closes the session

Issue: F-13903

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenrir Automated Review — PR #1360

Scan targets checked: wolfssh-src, wolfssh-bugs
Coverage: 2 of 3 in-scope changed file(s) opened by the reviewer; not opened: tests/unit.c

Fenrir result: Approved ✅

No new issues found in the changed files.

Advisory only — this automated result does not count as a GitHub approval.

Review tier: Lite

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.

4 participants