Repository navigation
Report WS_WANT_WRITE only while output is queued - #1404
ejohnstown wants to merge 2 commits into
Conversation
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #1404
Scan targets checked: wolfssh-src, wolfssh-bugs
Coverage: 5 of 5 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: Max
|
@claude review |
There was a problem hiding this comment.
Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.
Additional findings (outside the current diff — GitHub can't attach inline comments there):
-
🟣
src/wolfsftp.c— pre-existing: Non-blocking SFTP clients still get wolfSSH_get_error() == WS_WANT_WRITE with nothing queued when the peer window or a rekey holds a request. The remap to WS_WINDOW_FULL/WS_REKEYING was added only to the server path in wolfSSH_SFTP_read (~2027). wolfSSH_SFTP_buffer_send_finish still writes WS_WANT_WRITE whenever idx < sz (685-687). Fix: do the window/rekey mapping inside wolfSSH_SFTP_buffer_send_finish, so the server site and all 6 client sites are covered. Same pattern at 7 sites (wolfsftp.c:2024, 8452, 8639, 8777, 9001, 9289, 9851).Why this was flagged
Take a non-blocking client calling wolfSSH_SFTP_SetSTAT, Open, Close, Remove or a similar request whose packet is bigger than the peer's remaining channel window. Another trigger is a flush that starts a rekey. The new loop in wolfSSH_SFTP_buffer_send (wolfsftp.c:651-655) stops with idx < sz and nothing in the output buffer. wolfSSH_SFTP_buffer_send_finish then sets ssh->error = WS_WANT_WRITE (wolfsftp.c:686), and the client sites return WS_FATAL_ERROR (e.g. wolfsftp.c:8452-8455, 8639-8642). The caller then waits for the socket to become writable. It is always writable, so the caller either busy-loops or never runs the worker that would receive the WINDOW_ADJUST or finish the KEX. Issue #1401 describes exactly this on the server side. The PR fixes it only in wolfSSH_SFTP_read (wolfsftp.c:2026-2035), so client paths behave as they do on the base branch.
Verification: pre-existing. The client sites return WS_FATAL_ERROR with that error left in place: src/wolfsftp.c:8452-8455 (SetSTAT), 8639-8642 (Open), 9289-9292 (MKDIR). Only the server path in wolfSSH_SFTP_read (src/wolfsftp.c:2024-2036) remaps the error to WS_REKEYING or WS_WINDOW_FULL. So on the client paths, wolfSSH_get_error() still reports WS_WANT_WRITE while nothing is queued.
|
Re the pre-existing client finding: done. |
There was a problem hiding this comment.
🟡 Changes recommended
Bundled SFTP client loops treat WS_WINDOW_FULL—and WS_REKEYING for MKDIR—as terminal errors, abandoning retained requests instead of processing peer messages and resuming the operation.
1 open issue
What changed in this PR
Addresses #1401 by aligning non-blocking write-wait reporting with queued output across wolfSSH’s transport, worker, and SFTP paths.
Changes:
- Clears stale
WS_WANT_WRITEafter completed flushes and returns worker success when its flush resolves a blocked reply. - Continues SFTP sends across packet-size limits and distinguishes window exhaustion from rekey waits.
- Adds regression coverage for flush completion and stalled SFTP requests and replies.
| File | Description |
|---|---|
wolfssh/wolfsftp.h |
Declares an internal SFTP send-completion test hook. |
tests/regress.c |
Tests stale write status, packet limits, window stalls, and rekeying. |
src/wolfsftp.c |
Sends across packet limits and reports specific flow-control statuses. |
src/ssh.c |
Returns success after flushing a previously blocked reply. |
src/internal.c |
Clears stale WS_WANT_WRITE when output finishes flushing. |
Review effort: Balanced
A non-blocking SFTP server could leave wolfSSH_get_error() at WS_WANT_WRITE with nothing queued, so a caller waited on a socket that had nothing to send. - internal: a flush that empties the output buffer clears a stale WS_WANT_WRITE, as GetInputData() does for WS_WANT_READ - ssh: wolfSSH_worker() returns WS_SUCCESS once its own flush sends the reply DoReceive() blocked on - sftp: wolfSSH_SFTP_buffer_send() keeps sending past a packet-size cap until the buffer is done, the socket blocks or the window empties - sftp: the server reports a reply held back by the window or a rekey as WS_WINDOW_FULL or WS_REKEYING - regress: the stale flush error, the worker flush, the packet cap and a server reply held by the window or a rekey Issue: wolfSSL#1401
aeff658 to
f48585b
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #1404
Scan targets checked: wolfssh-src, wolfssh-bugs
Coverage: 1 of 3 in-scope changed file(s) opened by the reviewer; not opened: examples/sftpclient/sftpclient.c, tests/regress.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
A client request stopped by the peer's window or a rekey, with nothing queued, now reports WS_WINDOW_FULL or WS_REKEYING instead of WS_WANT_WRITE. wolfSSH_SFTP_buffer_send_finish() makes the call, so the server reply and every client request share it. - sftp: Open, Rename, Put's open and CHMOD keep their state on those codes, so a half-sent request is resumed, not sent again - sftpclient: mkdir, creat, chmod, get, put and rename retry on them - regress: each held request resumes once the window opens, goes out once and clears its state Issue: wolfSSL#1401
f48585b to
9280ce1
Compare

A non-blocking SFTP server or client could leave wolfSSH_get_error() at
WS_WANT_WRITE with nothing queued, so a caller waited on a socket that had
nothing to send.
worker returns WS_SUCCESS once its own flush sends a reply that blocked
WS_WINDOW_FULL or WS_REKEYING
Issue: #1401