mnpoonia opened a new pull request, #8604:
URL: https://github.com/apache/hbase/pull/8604

   ### Problem
   
   `TestLogLevel` fails intermittently in `setUp` when the MiniKDC port is 
already in use:
   
   ```
   org.apache.kerby.kerberos.kerb.KrbException: Failed to start 
DefaultKrbServer. Address already in use (Bind failed)
       at ...AbstractInternalKdcServer.start
       at ...SimpleKdcServer.start
       at org.apache.hadoop.minikdc.MiniKdc.start(MiniKdc.java:284)
       at 
org.apache.hadoop.hbase.http.log.TestLogLevel.setupMiniKdc(TestLogLevel.java:155)
   ```
   
   ### Root cause
   
   `setupMiniKdc` already retries on port conflicts, but only `catch 
(BindException e)`. The Kerby-backed `MiniKdc` does **not** throw 
`java.net.BindException` — it wraps the bind failure in a Kerby `KrbException`, 
and the cause chain carries **no** `BindException`; the conflict is only 
visible via the `"Address already in use"` message. So the retry is dead code 
and the first collision fails the test.
   
   Same block exists in two places:
   - `TestLogLevel.setupMiniKdc` (hbase-http)
   - `HBaseTestingUtil.setupMiniKdc` (hbase-server) — also affects e.g. 
`TestSecureRESTServer`, `TestSecureExport`.
   
   ### Fix
   
   Recognise a bind conflict regardless of wrapper type: `catch (Exception e)`, 
then a predicate that walks the whole cause chain and matches the `"Address 
already in use"` message; rethrow anything else so a genuine KDC misconfig is 
never masked.
   
   Deliberately **not** `catch (BindException | KrbException)`:
   - the message (not the type) is the discriminator — the cause chain has no 
`BindException`, and a future MiniKdc/Kerby could use a different wrapper;
   - a bare `KrbException` catch would still need the message check (a real 
misconfig is also a `KrbException`);
   - it avoids a compile-time import of a kerby type, which HBASE-29117 warns 
against (kerby version is unpinned; 1.x/2.x incompatible across Hadoop 
versions).
   
   ### Tests
   
   - `testKdcBindConflictSurfacesAsKrbException` — deterministic reproduction: 
occupies the KDC port on TCP+UDP, pins MiniKdc to it, asserts the failure is a 
Kerby `KrbException` (not a `BindException`) recognised by the predicate.
   - `testIsBindExceptionRecognizesKerbyWrappedBindFailure` — unit test for the 
predicate (wrapped `BindException`, message-only, and negative case).


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