-
Notifications
You must be signed in to change notification settings - Fork 594
Reset connection deadline before connection is released #1608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adjusts when the connection deadline is cleared by removing the early defer
reset and instead resetting the deadline inside the streaming goroutine just before the connection is released.
- Drop deferred reset of
c.conn.SetDeadline
immediately after setting context deadline. - Add explicit
c.conn.SetDeadline(time.Time{})
in the goroutine after both streams close. - Shift responsibility for clearing the deadline to just before
release
.
@@ -44,7 +44,6 @@ func (c *connect) query(ctx context.Context, release nativeTransportRelease, que | |||
// context level deadlines override any read deadline | |||
if deadline, ok := ctx.Deadline(); ok { | |||
c.conn.SetDeadline(deadline) | |||
defer c.conn.SetDeadline(time.Time{}) | |||
} | |||
|
|||
if err = c.sendQuery(body, &options); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a deadline was set on the connection, it isn't cleared when sendQuery
returns an error, which can leave a stale deadline on subsequent operations. Consider using defer
immediately after setting the deadline or explicitly clearing it in this error path.
if err = c.sendQuery(body, &options); err != nil { | |
if err = c.sendQuery(body, &options); err != nil { | |
c.conn.SetDeadline(time.Time{}) // Clear stale deadline |
Copilot uses AI. Check for mistakes.
@@ -80,6 +79,8 @@ func (c *connect) query(ctx context.Context, release nativeTransportRelease, que | |||
} | |||
close(stream) | |||
close(errors) | |||
|
|||
c.conn.SetDeadline(time.Time{}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This unconditional reset will clear any pre-existing deadlines—even if none were set for this query—which may unintentionally override other timeouts. Track whether you applied a context deadline and guard the reset accordingly.
c.conn.SetDeadline(time.Time{}) | |
if _, ok := ctx.Deadline(); !ok { | |
c.conn.SetDeadline(time.Time{}) | |
} |
Copilot uses AI. Check for mistakes.
@@ -80,6 +79,8 @@ func (c *connect) query(ctx context.Context, release nativeTransportRelease, que | |||
} | |||
close(stream) | |||
close(errors) | |||
|
|||
c.conn.SetDeadline(time.Time{}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we might need to do this for SetReadDeadline
too. As the SetDeadline is an override on the context. I am unsure what we're using exactly in our case.
p.s. thanks for jumping on this so quickly!
Summary
It's not well well-thought-out fix attempt for #1607.
Requires deep dive into edge cases.
Checklist
Delete items not relevant to your PR: