Repository navigation
Fix set_env abort and stale-session reconnect failure - #3
Conversation
…isconnect Agent-Logs-Url: https://github.com/ohto-ai/webssh_cpp/sessions/6c478c4f-3c7d-49d0-920e-e2bee2894f86 Co-authored-by: ohto-ai <46275725+ohto-ai@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Fixes two reconnection/robustness issues in the SSH WebSocket server: (1) channel-setenv failures no longer abort login, and (2) disconnected (“zombie”) sessions are pruned so they don’t block session reuse/reconnect.
Changes:
- Wrap the three
LC_WSSH_WEBSOCKET_*set_envcalls in a dedicatedtry/catchto downgrade server-sidechannel-setenvrejections to a warning. - In
ssh_pty_connection_manager::get_channel(), evict stale sessions (session == nullptr) for the targetsession_idbefore selecting a reusable session, and simplify the found/not-found logic.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/main.cpp |
Prevents set_env exceptions from propagating and failing the entire SSH login flow. |
src/ssh_connection/ssh_connection.cpp |
Removes disconnected sessions from the pool before reuse selection to prevent stale-session reconnect failures. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Find the first live session with available channel capacity. | ||
| range = sessions.equal_range(session_id); | ||
| auto it = std::find_if(range.first, range.second, [this](const auto &pair) { | ||
| return pair.second->channels.size() < max_channel_in_session; |
There was a problem hiding this comment.
max_channel_in_session is documented as “0 means no limit” (see ssh_connection.h:85), but the reuse predicate pair.second->channels.size() < max_channel_in_session will never be true when max_channel_in_session == 0, forcing creation of new sessions and preventing reuse. Consider treating 0 as unlimited here (e.g., max_channel_in_session == 0 || ...).
| return pair.second->channels.size() < max_channel_in_session; | |
| return max_channel_in_session == 0 || | |
| pair.second->channels.size() < max_channel_in_session; |
|
@copilot apply changes based on the comments in this thread |
…redicate Agent-Logs-Url: https://github.com/ohto-ai/webssh_cpp/sessions/0293adac-5c25-4031-9bb8-4f856c97a0ba Co-authored-by: ohto-ai <46275725+ohto-ai@users.noreply.github.com>
Applied in 06d9b4d. The session reuse predicate now treats |
Two independent bugs:
channel-setenvrejections (common on most SSH servers) abort the entire connection, and after Ctrl+D the session object lingers in the pool as a zombie that always wins the reuse search—blocking all subsequent reconnects with"Session is not opened".Changes
src/main.cpp— isolate set_env failuresWrap the three
LC_WSSH_WEBSOCKET_*env-var calls in their owntry/catchso a server-sidechannel-setenvrejection downgrades to awarninstead of propagating through the login handler and returning 403.src/ssh_connection/ssh_connection.cpp— prune zombie sessions before pool searchget_channel()now evicts sessions wheresession == nullptr(disconnected viaclose_channel→disconnect) before searching for a reusable slot. Replaces the fragilesession_iter == sessions.end()pattern with ashared_ptr-based found/not-found check against the correct range end (it != range.second), fixing the multi-session case too.