Skip to content

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion conn_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Preview

Copilot AI Jul 17, 2025

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.

Suggested change
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.

Expand Down Expand Up @@ -80,6 +79,8 @@ func (c *connect) query(ctx context.Context, release nativeTransportRelease, que
}
close(stream)
close(errors)

c.conn.SetDeadline(time.Time{})
Copy link
Preview

Copilot AI Jul 17, 2025

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.

Suggested change
c.conn.SetDeadline(time.Time{})
if _, ok := ctx.Deadline(); !ok {
c.conn.SetDeadline(time.Time{})
}

Copilot uses AI. Check for mistakes.

Copy link
Member

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!

release(c, err)
}()

Expand Down
Loading