mirror of
https://github.com/coder/coder.git
synced 2025-07-15 22:20:27 +00:00
fix: don't log disconnect error when the database is shutting down (#6309)
* fix: don't log disconnect error when the database is shutting down Seen in: https://github.com/coder/coder/actions/runs/4244980490/jobs/7379867681 * Generalize the query close error
This commit is contained in:
@ -27,3 +27,13 @@ func IsUniqueViolation(err error, uniqueConstraints ...UniqueConstraint) bool {
|
|||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsQueryCanceledError checks if the error is due to a query being canceled.
|
||||||
|
func IsQueryCanceledError(err error) bool {
|
||||||
|
var pqErr *pq.Error
|
||||||
|
if errors.As(err, &pqErr) {
|
||||||
|
return pqErr.Code.Name() == "query_canceled"
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
@ -644,7 +644,9 @@ func (api *API) workspaceAgentCoordinate(rw http.ResponseWriter, r *http.Request
|
|||||||
// This is a bug with unit tests that cancel the app context and
|
// This is a bug with unit tests that cancel the app context and
|
||||||
// cause this error log to be generated. We should fix the unit tests
|
// cause this error log to be generated. We should fix the unit tests
|
||||||
// as this is a valid log.
|
// as this is a valid log.
|
||||||
if !xerrors.Is(err, context.Canceled) {
|
//
|
||||||
|
// The pq error occurs when the server is shutting down.
|
||||||
|
if !xerrors.Is(err, context.Canceled) && !database.IsQueryCanceledError(err) {
|
||||||
api.Logger.Error(ctx, "failed to update agent disconnect time",
|
api.Logger.Error(ctx, "failed to update agent disconnect time",
|
||||||
slog.Error(err),
|
slog.Error(err),
|
||||||
slog.F("workspace", build.WorkspaceID),
|
slog.F("workspace", build.WorkspaceID),
|
||||||
|
Reference in New Issue
Block a user