Repository navigation
fix(server): keep a listener's slab slot for its whole lifetime - #1333
Merged
Merged
Conversation
The four proxies keep a listener's slab token inside the listener itself: `give_back_listener` hands the same token back on `deactivate-listener`, and a later `activate-listener` re-registers the socket under it. `deactivate-listener` nevertheless freed that slab slot, and `Server::ready` drops any event whose token the slab does not contain — so a reactivated HTTP, HTTPS or TCP listener served only the backlog its activation drained and then went silent, while the request had answered `ok`. UDP failed harder. Its activation installs a real `UdpListenerSession` at the listen token behind a `slab.contains` guard that was now false, so the socket was registered with no session behind it and every datagram was dropped. Once the freed key had been handed to an ordinary session, that same guard read true and the assignment overwrote a live session. A listener now owns exactly one slab slot for its whole `add-listener` -> `remove-listener` lifetime: deactivating puts back the same inert `ListenSession` placeholder that adding installed rather than freeing the slot. The retained token therefore stays valid, and the slab can no longer hand that key to a session — the overwrite is removed by construction rather than by another check. `remove-listener` becomes the release point, which also closes a leak that predates this change: no proxy's `remove_listener` touches the session slab, and the deactivation arms were the only code that ever freed a listener's slot, so removing a listener that had not been deactivated first stranded one slab key per add/remove cycle while `base_sessions_count` was decremented anyway. For UDP the stranded entry was worse than a key: it held the last `UdpListenerSession` reference, keeping the listener's `UdpSocket` open and keeping `Server::ready` dispatching to a listener the control plane had removed. The UDP activation path no longer answers `ok` when it cannot install its session; it returns a worker error instead. All four defects seen red. Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
requested review from
Wonshtrum and
llenotre
as code owners
September 18, 2026 17:49
This was referenced Sep 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Four defects, one root cause: a listener's slab slot did not live as long as the listener.
The defect
The four proxies keep a listener's slab token inside the listener:
give_back_listenerhandsthe same token back on
deactivate-listener, and a lateractivate-listenerre-registers thesocket under it.
deactivate-listenernevertheless freed that slab slot, andServer::readywrapsits whole body in
if self.sessions.borrow().slab.contains(session_token)— a miss is a silentno-op with no log.
So a reactivated HTTP, HTTPS or TCP listener is deaf: it serves only the backlog its activation
drained, then goes silent, while
activate-listeneransweredok.UDP failed harder. Its activation installs a real
UdpListenerSessionat the listen tokenbehind a
slab.containsguard that was now false, so the socket was registered with no sessionbehind it and every datagram was dropped. And once the freed key had been handed out to an ordinary
session, that same guard read true and the assignment overwrote a live session.
The fix
A listener now owns exactly one slab slot for its whole
add-listener→remove-listenerlifetime. Deactivating puts back the same inert
ListenSessionplaceholder that adding installedinstead of freeing the slot, so the retained token stays valid — and the slab can no longer hand
that key to a session, which removes the overwrite by construction rather than by another check.
remove-listenerbecomes the release point.The leak this also closes
No proxy's
remove_listenertouches the session slab, and the deactivation arms were the only codethat ever freed a listener's slot. Removing a listener that had not been deactivated first therefore
already stranded one slab key per add/remove cycle, while
base_sessions_countwas decrementedanyway. For UDP the stranded entry was worse than a key: it held the last
UdpListenerSessionreference, keeping the listener's
UdpSocketopen and keepingServer::readydispatching to alistener the control plane had removed.
Reserving the slot without making
remove-listenerrelease it would have converted thatpre-existing leak into a guaranteed one, which is why the two parts ship together.
Also
ActivateListenerfor UDP no longer answersWorkerResponse::okwhen it cannot install itssession — it returns a worker error. Previously it reached the identical state (active, socket
registered, placeholder slot) and reported success.
Tests — all four seen red
a_reactivated_tcp_listener_is_reachable_from_the_event_loop— red withreserve_listen_token→slab.remove: "a reactivated listener must still be dispatched byready()".removing_a_listener_releases_its_reserved_slot— red without theRemoveListenerrelease:"cycle 0: removing a listener must release its reserved slot".
deactivating_a_listener_drops_its_pending_accept_token— red without theaccept_readypurge.Each carries a
To SEE THIS RED:block naming the exact mutation, per the house convention.Local, on this branch rebased onto
3fcf4ec6: