Skip to content

ssh: Refactor disconnect handling to use context maps#11033

Open
u3s wants to merge 2 commits into
erlang:masterfrom
u3s:kuba/ssh/disconnect-context-refactoring
Open

ssh: Refactor disconnect handling to use context maps#11033
u3s wants to merge 2 commits into
erlang:masterfrom
u3s:kuba/ssh/disconnect-context-refactoring

Conversation

@u3s
Copy link
Copy Markdown
Contributor

@u3s u3s commented Apr 17, 2026

Replace positional arguments in send_disconnect/6,7 and disconnect/4
with a single map carrying code, details, module, line, and
state_name. This simplifies call sites and makes the disconnect
context extensible for future enrichment (e.g. event callbacks).

  • send_disconnect/6,7 -> send_disconnect/2,3 with map argument
  • disconnect/4 -> disconnect/1 with map argument
  • Rename macros to uppercase: ?send_disconnect -> ?SEND_DISCONNECT,
    ?DISCONNECT -> ?DISCONNECT_CONTEXT
  • Update ssh_dbg disconnect tracing to match new arities
  • Fix variable shadowing bug in terminate/3 where Reason was
    rebound to "Internal error"
  • Update all call sites across ssh_connection_handler,
    ssh_transport, ssh_fsm_kexinit, ssh_fsm_userauth_client,
    ssh_fsm_userauth_server

@u3s u3s self-assigned this Apr 17, 2026
@u3s u3s added the team:PS Assigned to OTP team PS label Apr 17, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 17, 2026

CT Test Results

    2 files     29 suites   25m 59s ⏱️
  500 tests   494 ✅  6 💤 0 ❌
1 709 runs  1 681 ✅ 28 💤 0 ❌

Results for commit 14ecf47.

♻️ This comment has been updated with latest results.

To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass.

See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally.

Artifacts

// Erlang/OTP Github Action Bot

u3s added 2 commits April 17, 2026 17:35
Replace positional arguments in send_disconnect/6,7 and disconnect/4
with a single map carrying code, details, module, line, and
state_name. This simplifies call sites and makes the disconnect
context extensible for future enrichment (e.g. event callbacks).

- send_disconnect/6,7 -> send_disconnect/2,3 with map argument
- disconnect/4 -> disconnect/1 with map argument
- Rename macros to uppercase: ?send_disconnect -> ?SEND_DISCONNECT,
  ?DISCONNECT -> ?DISCONNECT_CONTEXT
- Update ssh_dbg disconnect tracing to match new arities
- Fix variable shadowing bug in terminate/3 where Reason was
  rebound to "Internal error"
- Update all call sites across ssh_connection_handler,
  ssh_transport, ssh_fsm_kexinit, ssh_fsm_userauth_client,
  ssh_fsm_userauth_server
?CT_LOG automatically prepends pid, module, line, and function
name to log output, making manual inclusion of ?MODULE and ?LINE
redundant.

- Replace all 54 ct:log calls with ?CT_LOG
- Remove duplicate ?MODULE/?LINE/?FUNCTION_NAME/self() from
  format strings and argument lists where ?CT_LOG provides them
- Replace deprecated standalone catch expressions with try/catch
  and add ?CT_LOG for exception details including stacktrace
@u3s u3s force-pushed the kuba/ssh/disconnect-context-refactoring branch from d6afff9 to 14ecf47 Compare April 17, 2026 15:35
@u3s u3s requested a review from Mikaka27 April 17, 2026 16:56
@u3s u3s added the testing currently being tested, tag is used by OTP internal CI label Apr 17, 2026
@u3s u3s changed the title Kuba/ssh/disconnect context refactoring ssh: Refactor disconnect handling to use context maps Apr 17, 2026
Copy link
Copy Markdown
Contributor

@Mikaka27 Mikaka27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want documentation for the ContextMap in this PR?

Comment on lines +2118 to +2123
disconnect_fun(DisconnectType, Details, D) ->
disconnect_fun(#{type => DisconnectType, details => Details, code => undefined}, D).

disconnect_fun(#{details := Details} = _DisconnectContext, D) ->
Fun = ?GET_OPT(disconnectfun, (D#data.ssh_params)#ssh.opts),
Fun(Details).
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.

Previously we used ?CALL_FUN which wrapped a function execution in a 'catch', and now we call the function directly, are we ok with user's exception leaking from here?

@u3s u3s linked an issue Apr 24, 2026 that may be closed by this pull request
@u3s u3s requested a review from Mikaka27 April 30, 2026 18:38
@u3s u3s removed the testing currently being tested, tag is used by OTP internal CI label Apr 30, 2026
@u3s
Copy link
Copy Markdown
Contributor Author

u3s commented Apr 30, 2026

ping @alexandrejbr

Copy link
Copy Markdown
Contributor

@Mikaka27 Mikaka27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're fine with not catching disconnectfun's exception, looks good.

lists:join(", ", element(W,Own)),
lists:join(", ", element(C,CounterPart))]};
(_) ->
{"No common ~s algorithm", [Txt]}
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.

I still think that this was a bad choice. It would have been much more reasonable to pick a maximum of X peer algorithms and process those and claim the rest was truncated.

How many peer algorithm exist today? I guess the biggest list is in KEX.

%%%----------------------------------------------------------------
%%disconnect_fun({disconnect,Msg}, D) -> ?CALL_FUN(disconnectfun,D)(Msg);
disconnect_fun(Reason, D) -> ?CALL_FUN(disconnectfun,D)(Reason).
disconnect_fun(DisconnectType, Details, D) ->
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.

I see that you are bringing the disconnect type from #9157

Is that intentional, you still like the idea?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team:PS Assigned to OTP team PS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ssh connection troubleshooting

3 participants