You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(server): Goroutine leak in HTTP-Connect tunnel
This commit fixes a goroutine leak in the HTTP-Connect tunnel
(tunnel.go) that could occur during connection setup.
The leak happened when a backend agent disconnected at a very specific
time: after the server sent a DIAL_REQ but before the connection was
fully established. In this scenario, the cleanup logic was never called,
and the handler goroutine would hang forever.
I've refactored ServeHTTP to make it more robust and prevent this leak:
Added a deferred cleanup function: A defer block now acts as a safety
net. It uses a flag (established) to track whether the connection
succeeded. If the function exits for any reason before the connection is
established, this deferred code runs and guarantees that the pending
dial is removed from our tracking map.
Fixed a race condition with a single select: The old code had separate,
racy checks for different failure modes. I've replaced this with a
single, atomic select block that waits for all possible outcomes at
once: a successful connection, the client disconnecting, or the agent's
context being cancelled. This makes the logic much safer and easier to
follow.
Signed-off-by: Imran Pochi <imranpochi@microsoft.com>
0 commit comments