Skip to content

Commit

Permalink
Revert "Fix data race related to slog Logger"
Browse files Browse the repository at this point in the history
This reverts commit 085dbcc.
  • Loading branch information
Acconut committed Oct 4, 2024
1 parent c7aece8 commit 85ea4a5
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions pkg/handler/unrouted_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,8 @@ func (handler *UnroutedHandler) PostFile(w http.ResponseWriter, r *http.Request)
resp.Header["Location"] = url

handler.Metrics.incUploadsCreated()
c.log.Info("UploadCreated", "id", id, "size", size, "url", url)
c.log = c.log.With("id", id)
c.log.Info("UploadCreated", "size", size, "url", url)

if handler.config.NotifyCreatedUploads {
handler.CreatedUploads <- newHookEvent(c, info)
Expand Down Expand Up @@ -552,7 +553,8 @@ func (handler *UnroutedHandler) PostFileV2(w http.ResponseWriter, r *http.Reques
w.WriteHeader(104)

handler.Metrics.incUploadsCreated()
c.log.Info("UploadCreated", "id", id, "size", info.Size, "url", url)
c.log = c.log.With("id", id)
c.log.Info("UploadCreated", "size", info.Size, "url", url)

if handler.config.NotifyCreatedUploads {
handler.CreatedUploads <- newHookEvent(c, info)
Expand Down Expand Up @@ -615,6 +617,7 @@ func (handler *UnroutedHandler) HeadFile(w http.ResponseWriter, r *http.Request)
handler.sendError(c, err)
return
}
c.log = c.log.With("id", id)

if handler.composer.UsesLocker {
lock, err := handler.lockUpload(c, id)
Expand Down Expand Up @@ -712,6 +715,7 @@ func (handler *UnroutedHandler) PatchFile(w http.ResponseWriter, r *http.Request
handler.sendError(c, err)
return
}
c.log = c.log.With("id", id)

if handler.composer.UsesLocker {
lock, err := handler.lockUpload(c, id)
Expand Down Expand Up @@ -853,8 +857,7 @@ func (handler *UnroutedHandler) writeChunk(c *httpContext, resp HTTPResponse, up
maxSize = length
}

logger := c.log.With("id", info.ID)
logger.Info("ChunkWriteStart", "maxSize", maxSize, "offset", offset)
c.log.Info("ChunkWriteStart", "maxSize", maxSize, "offset", offset)

var bytesWritten int64
var err error
Expand All @@ -870,12 +873,12 @@ func (handler *UnroutedHandler) writeChunk(c *httpContext, resp HTTPResponse, up
// Update the read deadline for every successful read operation. This ensures that the request handler
// keeps going while data is transmitted but that dead connections can also time out and be cleaned up.
if err := c.resC.SetReadDeadline(time.Now().Add(handler.config.NetworkTimeout)); err != nil {
logger.Warn("NetworkTimeoutError", "error", err)
c.log.Warn("NetworkTimeoutError", "error", err)
}

// The write deadline is updated accordingly to ensure that we can also write responses.
if err := c.resC.SetWriteDeadline(time.Now().Add(2 * handler.config.NetworkTimeout)); err != nil {
logger.Warn("NetworkTimeoutError", "error", err)
c.log.Warn("NetworkTimeoutError", "error", err)
}
}

Expand All @@ -898,7 +901,7 @@ func (handler *UnroutedHandler) writeChunk(c *httpContext, resp HTTPResponse, up
// it in the response, if the store did not also return an error.
bodyErr := c.body.hasError()
if bodyErr != nil {
logger.Error("BodyReadError", "error", bodyErr.Error())
c.log.Error("BodyReadError", "error", bodyErr.Error())
if err == nil {
err = bodyErr
}
Expand All @@ -910,12 +913,12 @@ func (handler *UnroutedHandler) writeChunk(c *httpContext, resp HTTPResponse, up
if terminateErr := handler.terminateUpload(c, upload, info); terminateErr != nil {
// We only log this error and not show it to the user since this
// termination error is not relevant to the uploading client
logger.Error("UploadStopTerminateError", "error", terminateErr.Error())
c.log.Error("UploadStopTerminateError", "error", terminateErr.Error())
}
}
}

logger.Info("ChunkWriteComplete", "bytesWritten", bytesWritten)
c.log.Info("ChunkWriteComplete", "bytesWritten", bytesWritten)

// Send new offset to client
newOffset := offset + bytesWritten
Expand Down Expand Up @@ -966,7 +969,7 @@ func (handler *UnroutedHandler) emitFinishEvents(c *httpContext, resp HTTPRespon
resp = resp.MergeWith(resp2)
}

c.log.Info("UploadFinished", "id", info.ID, "size", info.Size)
c.log.Info("UploadFinished", "size", info.Size)
handler.Metrics.incUploadsFinished()

if handler.config.NotifyCompleteUploads {
Expand All @@ -986,6 +989,7 @@ func (handler *UnroutedHandler) GetFile(w http.ResponseWriter, r *http.Request)
handler.sendError(c, err)
return
}
c.log = c.log.With("id", id)

if handler.composer.UsesLocker {
lock, err := handler.lockUpload(c, id)
Expand Down Expand Up @@ -1115,6 +1119,7 @@ func (handler *UnroutedHandler) DelFile(w http.ResponseWriter, r *http.Request)
handler.sendError(c, err)
return
}
c.log = c.log.With("id", id)

if handler.composer.UsesLocker {
lock, err := handler.lockUpload(c, id)
Expand Down Expand Up @@ -1169,7 +1174,7 @@ func (handler *UnroutedHandler) terminateUpload(c *httpContext, upload Upload, i
handler.TerminatedUploads <- newHookEvent(c, info)
}

c.log.Info("UploadTerminated", "id", info.ID)
c.log.Info("UploadTerminated")
handler.Metrics.incUploadsTerminated()

return nil
Expand Down Expand Up @@ -1353,7 +1358,7 @@ func (handler *UnroutedHandler) lockUpload(c *httpContext, id string) (Lock, err

// No need to wrap this in a sync.OnceFunc because c.cancel will be a noop after the first call.
releaseLock := func() {
c.log.Info("UploadInterrupted", "id", id)
c.log.Info("UploadInterrupted")
c.cancel(ErrUploadInterrupted)
}

Expand Down

0 comments on commit 85ea4a5

Please sign in to comment.