mirror of
https://github.com/coder/coder.git
synced 2025-07-13 21:36:50 +00:00
fix: prevent error log when pgcoord
query is canceled (#8609)
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
package database
|
package database
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/lib/pq"
|
"github.com/lib/pq"
|
||||||
@ -40,7 +41,9 @@ func IsUniqueViolation(err error, uniqueConstraints ...UniqueConstraint) bool {
|
|||||||
func IsQueryCanceledError(err error) bool {
|
func IsQueryCanceledError(err error) bool {
|
||||||
var pqErr *pq.Error
|
var pqErr *pq.Error
|
||||||
if errors.As(err, &pqErr) {
|
if errors.As(err, &pqErr) {
|
||||||
return pqErr.Code.Name() == "query_canceled"
|
return pqErr.Code == "57014" // query_canceled
|
||||||
|
} else if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
@ -424,7 +424,7 @@ func (b *binder) writeOne(bnd binding) error {
|
|||||||
default:
|
default:
|
||||||
panic("unhittable")
|
panic("unhittable")
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil && !database.IsQueryCanceledError(err) {
|
||||||
b.logger.Error(b.ctx, "failed to write binding to database",
|
b.logger.Error(b.ctx, "failed to write binding to database",
|
||||||
slog.F("client_id", bnd.client),
|
slog.F("client_id", bnd.client),
|
||||||
slog.F("agent_id", bnd.agent),
|
slog.F("agent_id", bnd.agent),
|
||||||
|
Reference in New Issue
Block a user