name the AMQP connection in its own log lines #356

Closed
agent wants to merge 0 commits from worker/amqp-log-identity-bed2ca-2 into main
Member

Correction: preserve the real default handler

The first version extended ForgivingExceptionHandler. That was wrong because ConnectionFactory installs DefaultExceptionHandler by default.

What I checked

I inspected the installed amqp-client bytecode with javap. DefaultExceptionHandler extends StrictExceptionHandler, which extends ForgivingExceptionHandler. StrictExceptionHandler overrides return-listener, confirm-listener, blocked-listener, and consumer exception handling. Its strict channel path calls Channel.close(200, ...); the forgiving base only logs that consumer path.

AmqpConnectionFailureLogger now extends DefaultExceptionHandler. It still overrides only protected log(String, Throwable), so all strict handler methods remain inherited and only the log destination and connection identity change. The copied reset helper has a source comment that it mirrors the client private static helper and needs checking on amqp-client upgrades.

Baseline and strict behaviour tests

Both factories now assert their installed handler is a DefaultExceptionHandler, with this failure reason:

reply inbox must keep DefaultExceptionHandler: replacing the strict handler with a forgiving one changes when a channel is closed

The test also invokes handleConsumerException with a fake channel and checks that it receives one close call. This does not use a live broker. It proves the handler executes the strict channel-close path. It does not prove broker-side delivery or recovery behaviour.

Mutation

I changed the parent back to ForgivingExceptionHandler. The focused test failed with:

AmqpConnectionFailureLoggerTest.installedHandlersLogTheirOwnConnectionNamesAtErrorWithTheCause:30->installedStrictHandler:120 reply inbox must keep DefaultExceptionHandler: replacing the strict handler with a forgiving one changes when a channel is closed ==> Unexpected type, expected: <com.rabbitmq.client.impl.DefaultExceptionHandler> but was: <dev.ltms.fleet.msg.AmqpConnectionFailureLogger>
AmqpConnectionFailureLoggerTest.strictConsumerExceptionStillClosesItsChannel:94 DefaultExceptionHandler must close a channel after a consumer exception ==> expected: <1> but was: <0>

Connection identity

Both connection names remain in one helper and each failure event uses its own class logger. The ERROR message text remains:

AMQP connection fleetd-reply-inbox: An unexpected connection driver error occurred

Connection resets keep the client existing WARN-without-stack-trace behaviour. Other failures remain ERROR with their original throwable and stack trace. Automatic and topology recovery settings are unchanged.

Checks

$ /Users/dai.ha/Softwares/apache-maven/bin/mvn -Dtest=AmqpConnectionFailureLoggerTest test
Tests run: 5, Failures: 0, Errors: 0, Skipped: 0
BUILD SUCCESS

$ cd fleetd && /Users/dai.ha/Softwares/apache-maven/bin/mvn clean install
Tests run: 1377, Failures: 0, Errors: 0, Skipped: 0
BUILD SUCCESS

No daemon restart occurred.

## Correction: preserve the real default handler The first version extended `ForgivingExceptionHandler`. That was wrong because `ConnectionFactory` installs `DefaultExceptionHandler` by default. ### What I checked I inspected the installed amqp-client bytecode with `javap`. `DefaultExceptionHandler` extends `StrictExceptionHandler`, which extends `ForgivingExceptionHandler`. `StrictExceptionHandler` overrides return-listener, confirm-listener, blocked-listener, and consumer exception handling. Its strict channel path calls `Channel.close(200, ...)`; the forgiving base only logs that consumer path. `AmqpConnectionFailureLogger` now extends `DefaultExceptionHandler`. It still overrides only protected `log(String, Throwable)`, so all strict handler methods remain inherited and only the log destination and connection identity change. The copied reset helper has a source comment that it mirrors the client private static helper and needs checking on amqp-client upgrades. ### Baseline and strict behaviour tests Both factories now assert their installed handler is a `DefaultExceptionHandler`, with this failure reason: ```text reply inbox must keep DefaultExceptionHandler: replacing the strict handler with a forgiving one changes when a channel is closed ``` The test also invokes `handleConsumerException` with a fake channel and checks that it receives one close call. This does not use a live broker. It proves the handler executes the strict channel-close path. It does not prove broker-side delivery or recovery behaviour. ### Mutation I changed the parent back to `ForgivingExceptionHandler`. The focused test failed with: ```text AmqpConnectionFailureLoggerTest.installedHandlersLogTheirOwnConnectionNamesAtErrorWithTheCause:30->installedStrictHandler:120 reply inbox must keep DefaultExceptionHandler: replacing the strict handler with a forgiving one changes when a channel is closed ==> Unexpected type, expected: <com.rabbitmq.client.impl.DefaultExceptionHandler> but was: <dev.ltms.fleet.msg.AmqpConnectionFailureLogger> AmqpConnectionFailureLoggerTest.strictConsumerExceptionStillClosesItsChannel:94 DefaultExceptionHandler must close a channel after a consumer exception ==> expected: <1> but was: <0> ``` ### Connection identity Both connection names remain in one helper and each failure event uses its own class logger. The ERROR message text remains: ```text AMQP connection fleetd-reply-inbox: An unexpected connection driver error occurred ``` Connection resets keep the client existing WARN-without-stack-trace behaviour. Other failures remain ERROR with their original throwable and stack trace. Automatic and topology recovery settings are unchanged. ### Checks ```text $ /Users/dai.ha/Softwares/apache-maven/bin/mvn -Dtest=AmqpConnectionFailureLoggerTest test Tests run: 5, Failures: 0, Errors: 0, Skipped: 0 BUILD SUCCESS $ cd fleetd && /Users/dai.ha/Softwares/apache-maven/bin/mvn clean install Tests run: 1377, Failures: 0, Errors: 0, Skipped: 0 BUILD SUCCESS ``` No daemon restart occurred.
agent added 1 commit 2026-09-05 00:46:12 +02:00
Name AMQP connection failure logs
CI / contract (pull_request) Successful in 1m20s
CI / build (pull_request) Successful in 1m29s
d292522d00
agent added 1 commit 2026-09-05 00:53:49 +02:00
Preserve strict AMQP exception handling
CI / contract (pull_request) Successful in 1m4s
CI / build (pull_request) Successful in 1m46s
23f299e105
ltms closed this pull request 2026-09-05 01:01:42 +02:00
Some checks are pending
CI / contract (pull_request) Successful in 1m4s
CI / build (pull_request) Successful in 1m46s

Pull request closed

Sign in to join this conversation.