fix(mesh): a rejected first connect no longer leaks a retry supervisor
openSession's abort listener runs onEnd -> endSession -> scheduleRetry on every socket abort, including the ones where the connect promise rejected. A rejected connect means no caller ever received the Link, so nothing can close it and closeLinks never sees it — connectUntilDeadline pushes to meshLinks only on success. Every boot attempt against an unreachable teapot therefore left a live supervisor behind, reconnecting forever on a handle nobody holds. Before this branch the boot then threw and the process died with them. Now the teacup starts without that teapot, so they outlive the boot: close() the teacup, bring the teapot up afterwards, and three mesh:connect events fire for a URL contributing nothing to the graph, each holding an open socket. The initial openSession now marks the link closed and clears the pending timer before rethrowing. connectUntilDeadline is already the retry loop above this; a second one underneath it was never wanted. Reconnection for a link that did connect is untouched — that path runs through endSession on a session that dropped after the Link escaped, and the rejection handler here fires only on the first connect. The regression test asserts both sides: no mesh:connect on the teacup, and none on the teapot either, so a socket that opens without being adopted still fails it. Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
2 files changed
+75
-12
No files matched your search
+20
-5
@@ -499,10 +499,25 @@ export function connectLink(args: {
|
||||
}
|
||||
};
|
||||
|
||||
return openSession(sessionArgs(() => endSession(0))).then((session) => {
|
||||
link.manifest = session.manifest;
|
||||
adopt(session);
|
||||
return openSession(sessionArgs(() => endSession(0))).then(
|
||||
(session) => {
|
||||
link.manifest = session.manifest;
|
||||
adopt(session);
|
||||
|
||||
return link;
|
||||
});
|
||||
return link;
|
||||
},
|
||||
(error) => {
|
||||
// The first connect failed, so this `Link` never escaped — nobody holds it and nobody can
|
||||
// ever call `close()` on it. But `openSession`'s abort listener has already run `onEnd`,
|
||||
// which scheduled a retry: left alone, that supervisor reconnects forever to a handle no
|
||||
// caller has, and `closeLinks` cannot reach it because the link was never pushed to
|
||||
// `meshLinks`. Boot already retries above this (`connectUntilDeadline`), so a second
|
||||
// supervisor underneath it is pure leak — every failed attempt used to leave one behind.
|
||||
// Reconnection for a link that *did* connect is untouched: this path runs only on the
|
||||
// initial rejection, and a session that drops later still goes through `endSession`.
|
||||
state.closed = true;
|
||||
clearTimeout(state.retry);
|
||||
throw error;
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user