File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -162,7 +162,16 @@ func (re *RequestExtractor) SetOpenAIRequest(ctx *fiber.Ctx) error {
162162 ctx .Set ("X-Correlation-ID" , correlationID )
163163
164164 //c1, cancel := context.WithCancel(re.applicationConfig.Context)
165- c1 , cancel := context .WithCancel (ctx .Context ())
165+ // Use the application context as parent to ensure cancellation on app shutdown
166+ // We'll monitor the Fiber context separately and cancel our context when the request is canceled
167+ c1 , cancel := context .WithCancel (re .applicationConfig .Context )
168+ // Monitor the Fiber context and cancel our context when it's canceled
169+ // This ensures we respect request cancellation without causing panics
170+ go func () {
171+ <- ctx .Context ().Done ()
172+ // Fiber context was canceled (request completed or client disconnected)
173+ cancel ()
174+ }()
166175 // Add the correlation ID to the new context
167176 ctxWithCorrelationID := context .WithValue (c1 , CorrelationIDKey , correlationID )
168177
You can’t perform that action at this time.
0 commit comments