Skip to content

Commit b6855c2

Browse files
committed
jaegertracing should clean multipartform files at the end of its scope because we replaced original http.Request object with own
1 parent 4dc1483 commit b6855c2

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

jaegertracing/jaegertracing.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,19 @@ func TraceWithConfig(config TraceConfig) echo.MiddlewareFunc {
196196
}
197197

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

202213
// call next middleware / controller
203214
err = next(c)

0 commit comments

Comments
 (0)