Skip to content

feat(socket): rely on acceptors to notify listen socket closed - #229

Merged
keynslug merged 1 commit into
emqx:masterfrom
keynslug:fix/socket/avoid-monitor
Sep 3, 2026
Merged

keynslug merged 1 commit into
emqx:masterfrom
keynslug:fix/socket/avoid-monitor

Conversation

@keynslug

@keynslug keynslug commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR changes esockd_socket_listener implementation: now there's no socket:monitor/1 call.

This call forced use of socket registry facility for the listen socket and ALL subsequently accepted sockets. When socket registry is disabled, this helps to avoid small extra memory cost per each esockd_socket connection.

This commit changes `esockd_socket_listener` implementation: now
there's no `socket:monitor/1` call. This call forces use of socket
registry for the listen socket and ALL subsequently accepted
socket. This helps to avoid small extra memory cost per each
`esockd_socket` connection.
{noreply, State}.

handle_info({'DOWN', _MRef, socket, LSock, Info}, #state{lsock = LSock} = State) ->
error_logger:error_msg("[~s] Socket ~p closed: ~p", [?MODULE, LSock, Info]),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lost an error level log.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Right. The reasoning is that an OTP error report will follow anyway, since the listener terminates with abnormal reason.


init([ListenerRef, ConnSup, {Mod, Opts}, UpgradeFuns, Limiter, LSock]) ->
_ = erlang:process_flag(trap_exit, true),
{_Mod, Listener} = esockd_server:get_listener_prop(ListenerRef, listener),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

q: could this return undefined?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's set in esockd_socket_listener:start_supervised/1, which completes before any acceptors are started.

@keynslug
keynslug requested a review from zmstone September 3, 2026 06:29
@keynslug
keynslug merged commit 0243fdf into emqx:master Sep 3, 2026
7 checks passed
@keynslug
keynslug deleted the fix/socket/avoid-monitor branch September 3, 2026 06:45
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.

2 participants