File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -196,8 +196,19 @@ func TraceWithConfig(config TraceConfig) echo.MiddlewareFunc {
196
196
}
197
197
198
198
// 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
+ }()
201
212
202
213
// call next middleware / controller
203
214
err = next (c )
You can’t perform that action at this time.
0 commit comments