Skip to content

fix(control): drop connection on write timeout - #126

Open
bappisinsane wants to merge 1 commit into
jamesconwaydev:mainfrom
bappisinsane:fix/control-socket-write-timeout
Open

bappisinsane wants to merge 1 commit into
jamesconwaydev:mainfrom
bappisinsane:fix/control-socket-write-timeout

Conversation

@bappisinsane

Copy link
Copy Markdown

Fixes #125.

When a write times out, the control socket now aborts the transport so the buffered reply and the socket are dropped at once, and the per-uid connection count (released in _handle's finally) only comes down once the connection is really gone.

  • _handle aborts writer.transport on TimeoutError/connection errors.
  • CHANGELOG entry under [Unreleased] -> Fixed.

@jamesconwaydev jamesconwaydev left a comment •

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for picking this up, @bappisinsane, and so quickly. The fix is in the right place. Three things before I can merge it:

  1. A test. #125 asks for one that fails on main and passes with your change: shrink WRITE_TIMEOUT, have a command return a large reply, connect with a small SO_RCVBUF and don't read, then check the connection is closed after the timeout. Without it, nothing stops this coming back.

  2. Sign-off. The dco check needs a Signed-off-by: line on the commit. git commit --amend -s --no-edit and a force-push will sort it.

  3. A smaller change. writer.transport always exists on a StreamWriter, and abort() doesn't raise, so the getattr and suppress can go, and so can the leftover pass:

    except (ConnectionError, TimeoutError):
        writer.transport.abort()  # drop the unsent reply now, not when the client reads

    For the CHANGELOG line, say what a reader would notice, something like: "The control socket closes a connection whose client stops reading, instead of keeping it and its reply open after the write timeout (#125)."

I've approved the CI run for this commit, and I'll approve the next one when you push.

@bappisinsane

Copy link
Copy Markdown
Author

Addressed all three points:

  1. Simplified the handler to writer.transport.abort() (no getattr/suppress/pass), keeping except (ConnectionError, TimeoutError).
  2. Added Signed-off-by via git commit -s and force-pushed.
  3. Updated the CHANGELOG line to describe what a reader notices.

On the test: I haven't yet added the write-timeout regression test; I'll follow up with it. The change itself is minimal and matches the suggested snippet.

@jamesconwaydev

Copy link
Copy Markdown
Owner

Thanks, @bappisinsane. The code change is exactly what I was after, and so is the CHANGELOG line. What's holding it up now is the branch, plus the test you already mentioned.

The branch conflicts with main. 0.2.9 went out and moved everything under [Unreleased], so your CHANGELOG line needs a new ### Fixed heading there. GitHub won't start CI on a conflicting PR, which is why no checks show up and there's nothing for me to approve yet.

The first commit still has no sign-off. The dco check reads every commit in the PR, and only the second one has the line. Squashing fixes both problems in one go:

git reset --soft HEAD~2
git commit -s
git fetch https://github.com/jamesconwaydev/sentry-v2 main
git rebase FETCH_HEAD        # fix CHANGELOG.md, git add it, git rebase --continue
git push --force-with-lease

The test is the part I can't merge without. #125 has the recipe: shrink WRITE_TIMEOUT, have a command return a large reply, connect with a small SO_RCVBUF, don't read, and check the connection closes after the timeout. It should fail on main and pass with your change. Push it whenever you're ready, on this PR, and I'll approve the CI run once it's up.

@bappisinsane

Copy link
Copy Markdown
Author

Thanks for the detailed guidance. I'll squash both commits with sign-off, rebase onto main, fix the CHANGELOG heading under [Unreleased], and add the write-timeout regression test per #125. Will push with --force-with-lease and ping once CI is green.

@jamesconwaydev

Copy link
Copy Markdown
Owner

Same good news here, @bappisinsane: dco passes and lint, typecheck and test are green on 0564bf1.

Only the test is missing. #125 has the recipe, and tests/unit/test_control.py already shows how to start a server on a temporary socket path. What you're proving is that a client who stops reading gets closed once WRITE_TIMEOUT runs out. As on #127, check that it fails with your fix stashed before you push.

Signed-off-by: bappisinsane <108801304+bappisinsane@users.noreply.github.com>
@bappisinsane
bappisinsane force-pushed the fix/control-socket-write-timeout branch from 0564bf1 to 74844ed Compare November 3, 2026 16:49
@jamesconwaydev

Copy link
Copy Markdown
Owner

Checking in, @bappisinsane. The fix still looks right to me, and CI is green on 74844ed. Two small things stand between this and a merge:

  1. The regression test from Control socket keeps a connection open after its write timeout #125. tests/unit/test_control.py already has a client that connects and stops reading; what's missing is a check that the connection is gone, and the per-uid count is back down, once the write timeout fires. It should fail on main and pass here.
  2. 0.2.10 shipped while this was open, so the CHANGELOG line now sits under [0.2.9]. Move it up under ### Fixed in [Unreleased].

If life got busy, no problem. Say the word and I'll add the test on top of your commit, with your name kept on the fix and in the release notes. Either way, #79 is still held for you.

This branch has not been deployed

No deployments
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.

Control socket keeps a connection open after its write timeout

2 participants