Skip to content

echoserver: wait to write in the SFTP loop - #1250

Merged
padelsbach merged 2 commits into
wolfSSL:masterfrom
ejohnstown:sftp-worker-write-wait
Sep 16, 2026
Merged

padelsbach merged 2 commits into
wolfSSL:masterfrom
ejohnstown:sftp-worker-write-wait

Conversation

@ejohnstown

Copy link
Copy Markdown
Contributor

The SFTP retry branch continued past the iteration's only tcp_select(), which watches reads, so a peer that had stopped reading cost a spin rather than a wait. It now waits on write readiness instead.

  • wait with tcp_select_write() when a refused send leaves WS_WANT_WRITE; a buffered send with a willing socket still goes straight around
  • end the loop on an error-ready or failed descriptor, but retry an interrupted select() rather than tearing the session down
  • correct the ScpStreamRead() comment, which still claimed the helper was error-code transparent after it began draining a WS_EXTDATA and retrying the read

A send the socket refused leaves WS_WANT_WRITE, and the retry branch
continues past the only tcp_select() in the iteration, which watches
reads. Wait on write readiness there, so a peer that has stopped
reading costs a descriptor wait rather than a spin.

- a buffered send with a willing socket still goes straight around
- an error-ready or failed descriptor ends the loop
- an interrupted select() retries instead of ending the session
Copilot AI lite review requested due to automatic review settings September 14, 2026 21:48

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.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Pull request overview

Improves the SFTP worker loop in echoserver to avoid CPU spinning when the peer stops reading by waiting on write readiness, and updates SCP read helper documentation to match current behavior.

Changes:

  • Add write-readiness waiting (tcp_select_write) when WS_WANT_WRITE occurs in the SFTP loop.
  • Treat interrupted select() as retryable instead of tearing down the session.
  • Update ScpStreamRead() comment to reflect retry behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/wolfscp.c Updates ScpStreamRead() comment to reflect retry/pass-through behavior.
examples/echoserver/echoserver.c Adds EINTR mapping and waits for write readiness in the SFTP loop to prevent spinning.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread examples/echoserver/echoserver.c
Comment thread src/wolfscp.c Outdated
The helper drains a WS_EXTDATA and retries the read rather than handing
it back, so it is no longer error-code transparent for that one status.
Say so where the claim is made, and condense the rest.
@padelsbach
padelsbach merged commit 7449124 into wolfSSL:master Sep 16, 2026
185 checks passed
@ejohnstown
ejohnstown deleted the sftp-worker-write-wait branch September 16, 2026 18:28
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