prosgarz35 commented on PR #3198:
URL: https://github.com/apache/james-project/pull/3198#issuecomment-5806292515
### Additional Hardening: Heartbeat Listener Teardown & Graceful Empty
Continuation
This update addresses two edge cases during client disconnection:
#### 1. Mailbox Listener Teardown on Heartbeat Failure
* **Problem**:
When a periodic heartbeat write fails due to an abnormal network drop
(`Broken pipe` / socket disconnect), the exception handler stopped further
scheduling via `idleActive.set(false)`. However, because the client was already
disconnected, it would never send `DONE`. Consequently, `pushLineHandler`
would never fire, and `sm.unregisterIdle()` was never invoked. This left the
mailbox listener actively registered in `SelectedMailbox`, continuing to listen
for and process incoming mailbox events in vain for a dead client until
garbage collection.
* **Fix**:
Added defensive `if (sm != null) sm.unregisterIdle();` directly inside
the heartbeat exception catch block.
* **Benefit**:
Provides immediate self-healing: if keepalive delivery fails, the
mailbox listener is released on the spot, halting unnecessary event processing
for disconnected sessions.
#### 2. Graceful EOF / Disconnect Handling on Continuation Input
* **Problem**:
When a client or intermediate reverse proxy abruptly resets/terminates
the TCP connection, Netty flushes an empty line (`""`) to the line handler.
Previously, James treated this empty line as an unrecognized command, logged an
`INFO` warning, and attempted to write a tagged `BAD` response to an
already half-closed/dead socket, generating unnecessary I/O warnings.
* **Fix**:
- Added an explicit check for `line.isEmpty()`, treating it as a
client disconnect rather than a protocol syntax error.
- Lowered invalid continuation log messages from `INFO` to `DEBUG` to
keep production logs clean from spurious warnings caused by unstable mobile
clients.
* **Benefit**:
Eliminates futile socket write attempts to dead connections and
prevents log pollution in high-concurrency production environments.
--
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]