@@ -423,10 +423,12 @@ func processVideoProxy(c *fiber.Ctx, logger *zap.Logger, cache *ristretto.Cache[
423423 logger .Error ("failed to get object from s3" , zap .Error (err ), zap .String ("object" , objKey ))
424424 return c .Status (fiber .StatusInternalServerError ).SendString ("failed to fetch object from s3" )
425425 }
426- defer obj .Close ()
426+ // Note: Don't defer close here - SendStream will handle closing the reader
427+ // If we defer close, it will close the stream before SendStream finishes reading
427428
428429 // Return Partial Content
429- return c .Status (http .StatusPartialContent ).SendStream (obj )
430+ c .Status (http .StatusPartialContent )
431+ return c .SendStream (obj )
430432 }
431433
432434 // No range requested - stream entire file
@@ -435,12 +437,14 @@ func processVideoProxy(c *fiber.Ctx, logger *zap.Logger, cache *ristretto.Cache[
435437 logger .Error ("failed to get object from s3" , zap .Error (err ), zap .String ("object" , objKey ))
436438 return c .Status (fiber .StatusInternalServerError ).SendString ("failed to fetch object from s3" )
437439 }
438- defer obj .Close ()
440+ // Note: Don't defer close here - SendStream will handle closing the reader
441+ // If we defer close, it will close the stream before SendStream finishes reading
439442
440443 c .Set ("Accept-Ranges" , "bytes" )
441444 c .Set ("Content-Type" , contentType )
442445 c .Set ("Content-Length" , strconv .FormatInt (info .Size , 10 ))
443- return c .Status (http .StatusOK ).SendStream (obj )
446+ c .Status (http .StatusOK )
447+ return c .SendStream (obj )
444448 }
445449
446450 // Otherwise proxy via HTTP/HTTPS
0 commit comments