Skip to content

Commit

Permalink
jaegertracing should clean multipartform files at the end of its scop…
Browse files Browse the repository at this point in the history
…e because we replaced original http.Request object with own
  • Loading branch information
aldas committed Mar 1, 2023
1 parent 4dc1483 commit b6855c2
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions jaegertracing/jaegertracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,19 @@ func TraceWithConfig(config TraceConfig) echo.MiddlewareFunc {
}

// setup request context - add opentracing span
req = req.WithContext(opentracing.ContextWithSpan(req.Context(), sp))
c.SetRequest(req)
reqSpan := req.WithContext(opentracing.ContextWithSpan(req.Context(), sp))
c.SetRequest(reqSpan)
defer func() {
// as we have created new http.Request object we need to make sure that temporary files created to hold MultipartForm
// files are cleaned up. This is done by http.Server at the end of request lifecycle but Server does not
// have reference to our new Request instance therefore it is our responsibility to fix the mess we caused.
//
// This means that when we are on returning path from handler middlewares up in chain from this middleware
// can not access these temporary files anymore because we deleted them here.
if reqSpan.MultipartForm != nil {
reqSpan.MultipartForm.RemoveAll()
}
}()

// call next middleware / controller
err = next(c)
Expand Down

0 comments on commit b6855c2

Please sign in to comment.