Skip to content

ssh: Add event_funs option for unified event callbacks#11034

Open
u3s wants to merge 3 commits into
erlang:masterfrom
u3s:alexandrejbr/kuba/ssh/event_funs/OTP-20109
Open

ssh: Add event_funs option for unified event callbacks#11034
u3s wants to merge 3 commits into
erlang:masterfrom
u3s:alexandrejbr/kuba/ssh/event_funs/OTP-20109

Conversation

@u3s
Copy link
Copy Markdown
Contributor

@u3s u3s commented Apr 17, 2026

Introduce ssh_event module and event_funs option providing a
map-based callback mechanism for observing SSH connection events.
Event callbacks are fun/2 receiving (Event, Context) where Context
includes connection_ref, connection_info, and role.

Supported events: connected, disconnected, message_received.
Legacy callbacks (connectfun, disconnectfun) are called alongside
event_funs for backward compatibility.

  • New module ssh_event with process_event dispatcher
  • New option event_funs validated in ssh_options (map of fun/2)
  • connection_info_server/1 exported for internal event context
  • Legacy connectfun/3 bridged via ssh_event:connectfun/1 wrapper
  • Legacy disconnectfun/1 bridged via ssh_event:disconnectfun/1

Known TODOs:

  • [AP-5] event_funs_message_received test needs assertions
  • [AP-10] Skip legacy fun dispatch when default no-op
  • [AP-14] Reject legacy callbacks when event_funs configured

Based on work by Alexandre Rodrigues (PR-9157), adapted to use
the disconnect_context refactoring from PR-11033.

Co-authored-by: Alexandre Rodrigues alexandrejbr@live.com

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 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   26m 28s ⏱️
  502 tests   496 ✅  6 💤 0 ❌
1 711 runs  1 683 ✅ 28 💤 0 ❌

Results for commit 25fe31e.

♻️ 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
Copy link
Copy Markdown
Contributor Author

u3s commented Apr 17, 2026

relies on PR-11033, when it is merged and this PR is rebased we will only work on changes from d9ed3b2

Stuff skipped from PR-9157:

  • connection_info API adjustments
  • new arity options

ping @alexandrejbr

Introduce ssh_event module and event_funs option providing a
map-based callback mechanism for observing SSH connection events.
Event callbacks are fun/2 receiving (Event, Context) where Context
includes connection_ref, connection_info, and role.

Supported events: connected, disconnected, message_received.
Legacy callbacks (connectfun, disconnectfun) are called alongside
event_funs for backward compatibility.

- New module ssh_event with process_event dispatcher
- New option event_funs validated in ssh_options (map of fun/2)
- connection_info_server/1 exported for internal event context
- Legacy connectfun/3 bridged via ssh_event:connectfun/1 wrapper
- Legacy disconnectfun/1 bridged via ssh_event:disconnectfun/1

Known TODOs:
- [AP-5] event_funs_message_received test needs assertions
- [AP-10] Skip legacy fun dispatch when default no-op
- [AP-14] Reject legacy callbacks when event_funs configured

Based on work by Alexandre Rodrigues (PR-9157), adapted to use
the disconnect_context refactoring from PR-11033.

Co-authored-by: Alexandre Rodrigues <alexandrejbr@live.com>
@u3s u3s force-pushed the alexandrejbr/kuba/ssh/event_funs/OTP-20109 branch from d9ed3b2 to 25fe31e Compare April 17, 2026 17:37
@u3s u3s changed the title Alexandrejbr/kuba/ssh/event funs/otp 20109 ssh: Add event_funs option for unified event callbacks Apr 17, 2026
@u3s u3s linked an issue Apr 24, 2026 that may be closed by this pull request
@u3s
Copy link
Copy Markdown
Contributor Author

u3s commented Apr 30, 2026

ping @alexandrejbr

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

1 participant