Skip to content

apps/wolfssh, examples/client: resend stdin a send did not take - #1280

Open
yosuke-wolfssl wants to merge 1 commit into
wolfSSL:masterfrom
yosuke-wolfssl:fix/readInput-wantwrite
Open

yosuke-wolfssl wants to merge 1 commit into
wolfSSL:masterfrom
yosuke-wolfssl:fix/readInput-wantwrite

Conversation

@yosuke-wolfssl

@yosuke-wolfssl yosuke-wolfssl commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Problem

wolfSSH_stream_send() can return WS_WANT_WRITE without taking any of the caller's buffer: when earlier output is still queued and the socket won't take it, SendChannelData() tries to flush that queue first and returns before framing the new data. Both client stdin readers treated this as fatal. They printed "Couldn't send data" and stopped reading stdin, while the session stayed up.

  • examples/client -N hits this on master: nothing flushes a queued send there, so the next send's flush-first check returns WS_WANT_WRITE.
  • apps/wolfssh rarely hits it today, because its queued check flushes after each send. A follow-up library fix for SendChannelData(), which currently reports the caller's bytes as taken when it queued nothing, will make it return WS_WANT_WRITE in those cases. This PR has to land first.

Fix (apps/wolfssh/wolfssh.c, examples/client/client.c)

Both readers now keep the buffer and send it again:

Reader On WS_WANT_WRITE with nothing taken Gives up when
apps/wolfssh FlushQueuedSend() drives the worker until the queue drains, then resends the flush fails, or its 10 s FLUSH_QUEUE_TIMEOUT passes
examples/client waits 1 ms and resends, as it already did for WS_REKEYING; the resend flushes the queue first 10 s (SEND_RETRY_TIMEOUT) of waiting on the socket; a rekey restarts the wait

Both still print "Couldn't send data" when they give up. The apps/wolfssh comment on the queued check now describes the case it covers: a positive return with data still queued.

Verification

  • make check: 13/13 pass. gcc-13 -Werror: clean across 6 configs.
  • End to end: a WOLFSSH_TEST_BLOCK build with forced write blocks after connect, 40000 bytes on stdin, 3/3 runs each. "Library fix" is the follow-up above, applied locally:
Client master library fix only library fix + this PR
apps/wolfssh 38976 1849, "Couldn't send data" 40000
examples/client -N 0, "Couldn't send data" 0, "Couldn't send data" 40000
  • With every write blocked, both give up after 10 s with "Couldn't send data".
  • No committed test: the test harness can't link the client apps' entry points.

Not in this PR (already there before this change, will be fixed separately): Windows client_test() frees the session without stopping readInput(); both readers treat a short positive return as fully sent.

- readInput() in apps/wolfssh runs FlushQueuedSend() when
  wolfSSH_stream_send() returns WS_WANT_WRITE without taking the
  buffer, then sends the same buffer again; a failed flush still
  ends in "Couldn't send data".
- readInput() in examples/client retries WS_WANT_WRITE as it
  retries WS_REKEYING, for up to SEND_RETRY_TIMEOUT (10) seconds
  per buffer.
- The comment on the queued check in apps/wolfssh describes the
  positive-return case.
@yosuke-wolfssl yosuke-wolfssl self-assigned this Sep 29, 2026
Copilot AI balanced review requested due to automatic review settings September 29, 2026 07:27

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@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 #1280

Scan targets checked: wolfssh-src, wolfssh-bugs
Coverage: 2 of 2 in-scope changed file(s) opened by the reviewer

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