fix(coderd): fix panics by always checking for non-nil request logger (#18228)

This commit is contained in:
Mathias Fredriksson
2025-06-12 13:50:50 +03:00
committed by GitHub
parent c95d972d4e
commit 70723d3b51
4 changed files with 18 additions and 6 deletions

View File

@ -578,7 +578,9 @@ func (api *API) workspaceAgentLogs(rw http.ResponseWriter, r *http.Request) {
defer t.Stop()
// Log the request immediately instead of after it completes.
loggermw.RequestLoggerFromContext(ctx).WriteLog(ctx, http.StatusAccepted)
if rl := loggermw.RequestLoggerFromContext(ctx); rl != nil {
rl.WriteLog(ctx, http.StatusAccepted)
}
go func() {
defer func() {
@ -1047,7 +1049,9 @@ func (api *API) derpMapUpdates(rw http.ResponseWriter, r *http.Request) {
defer encoder.Close(websocket.StatusGoingAway)
// Log the request immediately instead of after it completes.
loggermw.RequestLoggerFromContext(ctx).WriteLog(ctx, http.StatusAccepted)
if rl := loggermw.RequestLoggerFromContext(ctx); rl != nil {
rl.WriteLog(ctx, http.StatusAccepted)
}
go func(ctx context.Context) {
// TODO(mafredri): Is this too frequent? Use separate ping disconnect timeout?
@ -1501,7 +1505,9 @@ func (api *API) watchWorkspaceAgentMetadata(
defer sendTicker.Stop()
// Log the request immediately instead of after it completes.
loggermw.RequestLoggerFromContext(ctx).WriteLog(ctx, http.StatusAccepted)
if rl := loggermw.RequestLoggerFromContext(ctx); rl != nil {
rl.WriteLog(ctx, http.StatusAccepted)
}
// Send initial metadata.
sendMetadata()