Manager: fix race condition in logging of worker properties

Dereferencing the `w *persistence.Worker` pointer should happen directly
in the function call, not in the zerolog callback function.
This commit is contained in:
Sybren A. Stüvel 2022-04-21 18:29:10 +02:00
parent bb1acef054
commit 79bac3a5f3

View File

@ -65,12 +65,16 @@ func requestWorkerStore(e echo.Context, w *persistence.Worker) {
req := e.Request()
reqCtx := context.WithValue(req.Context(), workerKey, w)
// Take copies now to avoid race conditions later.
wUUID := w.UUID
wName := w.Name
// Update the logger in this context to reflect the Worker.
l := zerolog.Ctx(reqCtx)
l.UpdateContext(func(c zerolog.Context) zerolog.Context {
return c.
Str("wUUID", w.UUID).
Str("wName", w.Name)
Str("wUUID", wUUID).
Str("wName", wName)
})
e.SetRequest(req.WithContext(reqCtx))