suvodeep-pyne opened a new pull request, #20442:
URL: https://github.com/apache/pinot/pull/20442

   ## Problem
   
   `S3PinotFS.retryWithS3CredentialRefresh` treats every S3 401/403 as expired 
credentials. It calls `initOrRefreshS3Client()`, which builds a new S3 client 
and closes the old one (#16553).
   
   Two things are wrong when the 403 is an `AccessDenied`:
   
   - The refresh cannot help. The credentials are valid but not permitted, and 
the new client gets its credentials from the same source.
   - Closing the old client breaks every call that is still using it:
     - a streamed read that is in flight fails with `SocketException: Socket 
closed`;
     - when the client was passed to `init(S3Client, ...)`, every other holder 
of that client fails with `IllegalStateException: Connection pool shut down` 
from then on.
   
   So one path that a role may not access breaks unrelated calls on other paths.
   
   ## Change
   
   A 403 whose S3 error code is `AccessDenied` is no longer retried. 
`retryWithS3CredentialRefresh` throws an `IOException` with the original 
`S3Exception` as its cause. There is no refresh, no new client, no close and no 
second request.
   
   Every other 401/403 keeps the refresh and the retry. This includes a 403 
from a HEAD request, which has no body and therefore no error code.
   
   The production change is 6 lines of code in `S3PinotFS` plus Javadoc.
   
   ## Compatibility
   
   - No config, API or format change.
   - The exception type does not change. On master, a denial that persists 
after the retry already reaches the caller as an `IOException` with the 
`S3Exception` as its cause. Only the message differs: `S3 denied access to the 
request` instead of `Unexpected exception during S3 operation after credential 
refresh`.
   - A denied call now makes one S3 request instead of two, and no longer logs 
the refresh warnings.
   - Behavior that changes on purpose: if a role session is revoked and S3 
answers `AccessDenied`, `S3PinotFS` no longer rebuilds its client. The 
credentials provider's own refresh replaces the session.
   
   ## Testing
   
   `S3PinotFSCredentialRefreshTest` (new), with a mocked `S3Client` passed to 
the three-argument `init`:
   
   - A 403 `AccessDenied` gives an `IOException` with that exception as its 
cause, exactly one request, and no `close()` on the client. On master this test 
fails with `NeverWantedButInvoked: s3Client.close()`.
   - These errors each refresh once, and only then retry: a 403 
`InvalidAccessKeyId`, a 403 with a null error code (as a HEAD returns it), a 
403 without error details, a 403 `accessdenied` (the match is exact) and a 401 
`AccessDenied`.
   
   All 85 tests of `pinot-s3` pass, including `S3PinotFSTest` (S3Mock in 
Docker). Spotless, checkstyle and the license checks pass.
   
   Checked by hand against a real S3 API: MinIO in Docker, with a policy that 
denies one prefix to the user. The same program ran against the classes of 
master (`2f8fd729c3`) and of this branch.
   
   | Scenario | master | this PR |
   |---|---|---|
   | One `S3PinotFS`. A streamed 16 MiB read is in flight while another call on 
the same instance is denied. | The read fails with `SocketException: Socket 
closed`. | The read completes; the SHA-256 matches. |
   | One `S3Client` passed to two `S3PinotFS`. One is denied, then the other 
calls `exists()`. | `IllegalStateException: Connection pool shut down` | 
`exists()` returns `true`. |
   
   ## Not in this PR
   
   These need more than a small change and will follow separately:
   
   - A denial that S3 reports on a HEAD request (`exists`, `length`, 
`lastModified`) has no error code, so it still refreshes and closes the client.
   - Other 403 codes such as `InvalidAccessKeyId` and `SignatureDoesNotMatch` 
still refresh.
   - On those paths, a client passed to `init(S3Client, ...)` is still closed, 
and parts of the keys are still logged.
   - S3 reports an expired token as a 400, which does not refresh.
   


-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to