Skip to content

fix: close the socket when the metadata exchange fails - #568

Merged
enocom merged 1 commit into
mainfrom
telemetry-3-classify-failures
Sep 24, 2026
Merged

enocom merged 1 commit into
mainfrom
telemetry-3-classify-failures

Conversation

@enocom

@enocom enocom commented Sep 18, 2026 •

Copy link
Copy Markdown
Member

The metadata exchange runs on an established TLS socket that nothing
outside metadata_exchange holds a reference to. A failure there — a
socket timeout, a short read, a malformed response, a token refresh
error — left that socket open until the garbage collector reclaimed it,
so a caller retrying a failing dial in a loop accumulated connections it
could not close.

ctx.wrap_socket needs no equivalent handling: it detaches the raw socket
and closes the file descriptor itself if the handshake fails
(ssl.SSLSocket._create ends in a bare except: that calls
self.close()).

Related to #449.

Comment thread README.md Outdated
Comment thread tests/unit/test_exceptions.py Outdated
The metadata exchange runs on an established TLS socket that nothing
outside metadata_exchange holds a reference to. A failure there — a
socket timeout, a short read, a malformed response, a token refresh
error — left that socket open until the garbage collector reclaimed it,
so a caller retrying a failing dial in a loop accumulated connections it
could not close.

ctx.wrap_socket needs no equivalent handling: it detaches the raw socket
and closes the file descriptor itself if the handshake fails.
@enocom enocom changed the title feat: classify connection failures fix: close the socket when the metadata exchange fails Sep 23, 2026
@enocom
enocom force-pushed the telemetry-3-classify-failures branch from 37fef56 to b24ad19 Compare September 23, 2026 03:55
@enocom

enocom commented Sep 23, 2026

Copy link
Copy Markdown
Member Author

@rhatgadkar-goog I agree the metadata exchange should remain a private implementation detail. As I started working through this, I realized there's a simpler way to capture the dial result (the various failures and success). So in the meantime, I've converted this into a fix of a problem I discovered -- failed metadata exchanges don't close the socket.

This is both a good bug fix and also sets up later PRs in the chain to capture the failure type. PTAL.

@enocom
enocom merged commit 0f3dd8f into main Sep 24, 2026
21 checks passed
@enocom
enocom deleted the telemetry-3-classify-failures branch September 24, 2026 02:45
@enocom
enocom restored the telemetry-3-classify-failures branch September 24, 2026 04:44
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