@@ -171,7 +171,9 @@ func writeStartupDecisions(w http.ResponseWriter, r *http.Request, filters map[s
171171 decisionJSON , _ := json .Marshal (decision )
172172
173173 if needComma {
174- w .Write ([]byte ("," ))
174+ if _ , err := w .Write ([]byte ("," )); err != nil {
175+ return err
176+ }
175177 } else {
176178 needComma = true
177179 }
@@ -231,7 +233,9 @@ func writeDeltaDecisions(w http.ResponseWriter, r *http.Request, filters map[str
231233 decisionJSON , _ := json .Marshal (decision )
232234
233235 if needComma {
234- w .Write ([]byte ("," ))
236+ if _ , err := w .Write ([]byte ("," )); err != nil {
237+ return err
238+ }
235239 } else {
236240 needComma = true
237241 }
@@ -267,65 +271,75 @@ func (c *Controller) StreamDecisionChunked(w http.ResponseWriter, r *http.Reques
267271 w .Header ().Set ("Content-Type" , "application/json" )
268272 w .Header ().Set ("Transfer-Encoding" , "chunked" )
269273 w .WriteHeader (http .StatusOK )
270- w .Write ([]byte (`{"new": [` )) // Write initial JSON structure
274+ if _ , err := w .Write ([]byte (`{"new": [` )); err != nil { // Write initial JSON structure
275+ return err
276+ }
271277
272278 // if the blocker just started, return all decisions
273279 if val , ok := r .URL .Query ()["startup" ]; ok && val [0 ] == "true" {
274280 // Active decisions
275281 err := writeStartupDecisions (w , r , filters , c .DBClient .QueryAllDecisionsWithFilters )
276282 if err != nil {
277283 log .Errorf ("failed sending new decisions for startup: %v" , err )
278- w .Write ([]byte (`], "deleted": []}` ))
284+ _ , _ = w .Write ([]byte (`], "deleted": []}` ))
279285 if hasFlusher {
280286 flusher .Flush ()
281287 }
282288
283289 return err
284290 }
285291
286- w .Write ([]byte (`], "deleted": [` ))
292+ if _ , err := w .Write ([]byte (`], "deleted": [` )); err != nil {
293+ return err
294+ }
287295 // Expired decisions
288296 err = writeStartupDecisions (w , r , filters , c .DBClient .QueryExpiredDecisionsWithFilters )
289297 if err != nil {
290298 log .Errorf ("failed sending expired decisions for startup: %v" , err )
291- w .Write ([]byte (`]}` ))
299+ _ , _ = w .Write ([]byte (`]}` ))
292300 if hasFlusher {
293301 flusher .Flush ()
294302 }
295303
296304 return err
297305 }
298306
299- w .Write ([]byte (`]}` ))
307+ if _ , err := w .Write ([]byte (`]}` )); err != nil {
308+ return err
309+ }
300310 if hasFlusher {
301311 flusher .Flush ()
302312 }
303313 } else {
304314 err = writeDeltaDecisions (w , r , filters , bouncerInfo .LastPull , c .DBClient .QueryNewDecisionsSinceWithFilters )
305315 if err != nil {
306316 log .Errorf ("failed sending new decisions for delta: %v" , err )
307- w .Write ([]byte (`], "deleted": []}` ))
317+ _ , _ = w .Write ([]byte (`], "deleted": []}` ))
308318 if hasFlusher {
309319 flusher .Flush ()
310320 }
311321
312322 return err
313323 }
314324
315- w .Write ([]byte (`], "deleted": [` ))
325+ if _ , err := w .Write ([]byte (`], "deleted": [` )); err != nil {
326+ return err
327+ }
316328
317329 err = writeDeltaDecisions (w , r , filters , bouncerInfo .LastPull , c .DBClient .QueryExpiredDecisionsSinceWithFilters )
318330 if err != nil {
319331 log .Errorf ("failed sending expired decisions for delta: %v" , err )
320- w .Write ([]byte ("]}" ))
332+ _ , _ = w .Write ([]byte ("]}" ))
321333 if hasFlusher {
322334 flusher .Flush ()
323335 }
324336
325337 return err
326338 }
327339
328- w .Write ([]byte ("]}" ))
340+ if _ , err := w .Write ([]byte ("]}" )); err != nil {
341+ return err
342+ }
329343 if hasFlusher {
330344 flusher .Flush ()
331345 }
@@ -439,7 +453,8 @@ func (c *Controller) StreamDecision(w http.ResponseWriter, r *http.Request) {
439453
440454 if err == nil {
441455 // Only update the last pull time if no error occurred when sending the decisions to avoid missing decisions
442- // Do not reuse the context provided by gin because we already have sent the response to the client, so there's a chance for it to already be canceled
456+ // Use a background context since we've already sent the response and the request context may be canceled
457+ //nolint:contextcheck // We intentionally use context.Background() here since the response is already sent
443458 if err := c .DBClient .UpdateBouncerLastPull (context .Background (), streamStartTime , bouncerInfo .ID ); err != nil {
444459 log .Errorf ("unable to update bouncer '%s' pull: %v" , bouncerInfo .Name , err )
445460 }
0 commit comments