gaborgsomogyi commented on PR #28012:
URL: https://github.com/apache/flink/pull/28012#issuecomment-4325923918

   I think `seek(contentLength)` triggers S3 416 when a stream is open.
   
   When seeking to exactly `contentLength` (a valid EOF-boundary seek) with an 
open stream, the current code calls `openStreamAtCurrentPosition()` 
unconditionally. This issues a range request bytes=contentLength-, which starts 
one byte past the last byte. Per RFC 7233, this range is unsatisfiable and S3 
returns 416.
   
   The fix: when seeking to contentLength, release the existing stream but do 
not reopen it. Any subsequent read() will return -1 immediately by the position 
check, so an open stream at EOF serves no purpose.                              
       
      
   ```
     if (desired != position) {                                                 
                                                                                
                                                                                
       
         position = desired;                                                    
                                                                                
                                                                                
       
         if (currentStream != null) {                                           
                                                                                
                                                                                
       
             if (desired >= contentLength) {                                    
                                                                                
                                                                                
       
                 releaseStreams();                                              
                                                                                
                                                                                
       
             } else {                                                           
                                                                                
                                                                                
       
                 openStreamAtCurrentPosition();                                 
                                                                                
                                                                                
       
             }                                                                  
                                                                                
                                                                                
       
         }                                                                      
                                                                                
                                                                                
       
     }                                                                          
                                                                                
                                                                                
       
   ```
                                                                                
                                                                                
                                                                                
       
   `releaseStreams()` is called directly (not via 
`openStreamAtCurrentPosition()`) because `seek()` already holds the lock. The 
>= guard instead of == is defensive — desired > contentLength is already 
rejected earlier, but this makes the branch  self-contained against future 
refactoring.
   
   The same root cause exists in `skip()` and in 
`read()`/`read(byte[],int,int)` where `lazyInitialize()` is called before the 
EOF position check - but those are separate fixes.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to