-
Notifications
You must be signed in to change notification settings - Fork 121
ssh: flush the worker's queued output and report what it is waiting on #1213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2618,20 +2618,17 @@ static void* HandleConnection(void* arg) | |
| wolfSSH_Log(WS_LOG_INFO, "[SSHD] Attempting to close down connection"); | ||
| ret = wolfSSH_shutdown(ssh); | ||
|
|
||
| /* peer hung up, stop shutdown */ | ||
| if (ret == WS_SOCKET_ERROR_E) { | ||
| /* peer hung up or the channel is already gone, stop shutdown */ | ||
| if (ret == WS_SOCKET_ERROR_E || ret == WS_CHANNEL_CLOSED) { | ||
| ret = 0; | ||
| } | ||
|
|
||
| error = wolfSSH_get_error(ssh); | ||
| if (error != WS_SOCKET_ERROR_E && | ||
| (error == WS_WANT_READ || error == WS_WANT_WRITE)) { | ||
| if (ret == WS_WANT_READ || ret == WS_WANT_WRITE) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shutdown drain is skipped when the owed flush lives only in ssh-error · Logic errors
Fix: Also enter the drain when There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Graceful-shutdown drain loop is skipped when only a flush is owed · Channel handling errors The drain gate now reads Fix: Also enter the drain loop when |
||
| int maxAttempt = 10; /* make 10 attempts max before giving up */ | ||
| int attempt; | ||
|
|
||
| for (attempt = 0; attempt < maxAttempt; attempt++) { | ||
| ret = wolfSSH_worker(ssh, NULL); | ||
| error = wolfSSH_get_error(ssh); | ||
|
|
||
| /* peer successfully closed down gracefully */ | ||
| if (ret == WS_CHANNEL_CLOSED) { | ||
|
|
@@ -2645,9 +2642,11 @@ static void* HandleConnection(void* arg) | |
| break; | ||
| } | ||
|
|
||
| if (ret == WS_FATAL_ERROR && | ||
| (error != WS_WANT_READ && | ||
| error != WS_WANT_WRITE)) { | ||
| /* Keep draining while the socket blocks or the peer is still | ||
| * talking. Anything else is a failure worth giving up on. */ | ||
| if (ret != WS_SUCCESS && ret != WS_WANT_READ && | ||
| ret != WS_WANT_WRITE && ret != WS_CHAN_RXD && | ||
| ret != WS_EXTDATA && ret != WS_REKEYING) { | ||
| break; | ||
| } | ||
| #ifdef _WIN32 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1383,7 +1383,7 @@ static int sftp_worker(thread_ctx_t* threadCtx) | |
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sftp_worker pre-select flush loop becomes an unbounded busy-wait · Channel handling errors
Related known finding #10544 (similar but distinct): Both findings affect echoserver worker-side SSH I/O handling, but #10544 is ssh_worker’s loss of unsent tails after partial writes, whereas this is sftp_worker’s unbounded retry loop on an owed flush; the faulting operations, root causes, and required patches differ. Fix: Bound the loop with a |
||
|
|
||
| do { | ||
| if (ret == WS_WANT_WRITE || ret == WS_CHAN_RXD || | ||
| if (ret == WS_CHAN_RXD || error == WS_WANT_WRITE || | ||
| wolfSSH_SFTP_PendingSend(ssh)) { | ||
| /* Yes, process the SFTP data. */ | ||
| ret = wolfSSH_SFTP_read(ssh); | ||
|
|
@@ -1639,14 +1639,12 @@ static THREAD_RETURN WOLFSSH_THREAD server_worker(void* vArgs) | |
| if (error != WS_SOCKET_ERROR_E && error != WS_FATAL_ERROR) { | ||
| ret = wolfSSH_shutdown(threadCtx->ssh); | ||
|
|
||
| /* peer hung up, stop shutdown */ | ||
| if (ret == WS_SOCKET_ERROR_E) { | ||
| /* peer hung up or the channel is already gone, stop shutdown */ | ||
| if (ret == WS_SOCKET_ERROR_E || ret == WS_CHANNEL_CLOSED) { | ||
| ret = 0; | ||
| } | ||
|
|
||
| error = wolfSSH_get_error(threadCtx->ssh); | ||
| if (error != WS_SOCKET_ERROR_E && | ||
| (error == WS_WANT_READ || error == WS_WANT_WRITE)) { | ||
| if (ret == WS_WANT_READ || ret == WS_WANT_WRITE) { | ||
| int maxAttempt = 10; /* make 10 attempts max before giving up */ | ||
| int attempt; | ||
|
|
||
|
|
@@ -1681,6 +1679,10 @@ static THREAD_RETURN WOLFSSH_THREAD server_worker(void* vArgs) | |
| } | ||
| } | ||
|
|
||
| /* The report below names how the connection ended, and the shutdown | ||
| * drain refreshes error only on the paths that enter it. */ | ||
| error = wolfSSH_get_error(threadCtx->ssh); | ||
|
|
||
| if (threadCtx->fd != -1) { | ||
| WCLOSESOCKET(threadCtx->fd); | ||
| threadCtx->fd = -1; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.