Skip to content

Commit 97ac7b9

Browse files
committed
fix: prevent error log when pgcoord query is canceled.
I believe this is what has been causing the `TestReplicas` flakes. There's a race condition where if a query was in flight while the `pgcoord` was closing, it would log an error. The error log then fails the test since somewhere along the line we're creating a `slogtest` logger.
1 parent 16cd1a6 commit 97ac7b9

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

enterprise/tailnet/pgcoord.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ func (b *binder) writeOne(bnd binding) error {
424424
default:
425425
panic("unhittable")
426426
}
427-
if err != nil {
427+
if err != nil && !pqErrIsCanceled(err) {
428428
b.logger.Error(b.ctx, "failed to write binding to database",
429429
slog.F("client_id", bnd.client),
430430
slog.F("agent_id", bnd.agent),
@@ -434,6 +434,12 @@ func (b *binder) writeOne(bnd binding) error {
434434
return err
435435
}
436436

437+
// This is returned when the context is canceled on a running query. pq does not
438+
// export an error for this.
439+
func pqErrIsCanceled(err error) bool {
440+
return err.Error() == "pq: canceling statement due to user request"
441+
}
442+
437443
// storeBinding stores the latest binding, where we interpret node == nil as removing the binding. This keeps the map
438444
// from growing without bound.
439445
func (b *binder) storeBinding(bnd binding) {

0 commit comments

Comments
 (0)