[ 
https://issues.apache.org/jira/browse/JAMES-4233?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

ilya terskov updated JAMES-4233:
--------------------------------
    Description: 
h1. *Context & Motivation*

    While Apache James has adopted Project Reactor for modern, non-blocking 
I/O, the IMAP IDLE implementation still retained legacy synchronous primitives 
and fragile lifecycle management. Under real-world workloads—particularly with
  high event concurrency and unstable client connections (mobile networks, NAT 
expirations, abrupt client drops)—these gaps led to thread pool exhaustion, 
lingering ghost connections, and subtle protocol race conditions.

h1. *What PR #3198 Achieves*

    This PR hardens the IMAP IDLE subsystem through targeted, 
backward-compatible improvements centered on three core architectural pillars:

    1. **Fully Non-Blocking Event Flow**:
       Migrates internal event synchronization from blocking primitives 
(`CountDownLatch::await`) to native reactive constructs (`Sinks.One`), ensuring 
Reactor and Netty worker threads are never held up waiting for handshake
  completions.

    2. **Defensive Lifecycle & Resource Management**:
       Guarantees deterministic cleanup across both happy paths and edge cases 
(unannounced client disconnects, mailbox deselection, and I/O write failures). 
Listener registrations and scheduled heartbeat tasks now cleanly self-heal
  and release session references immediately rather than relying on delayed 
garbage collection.

    3. **Strict Protocol Compliance & Network Robustness**:
       - Aligns Netty idle state tracking with RFC 2177, ensuring 
dead/half-open client connections are reliably detected even when outbound 
server heartbeats are actively running.
       - Eliminates protocol data races by ensuring clean response ordering 
between untagged mailbox updates and terminal tagged completion statuses.
       - Provides fault-tolerant handling of line delimiters and immediate 
buffer flushing to prevent artificial client handshake latency.

    ### Expected Impact
    Greatly improved stability under heavy mail delivery, lower heap footprint 
from eliminating zombie sessions, and cleaner server logs without breaking any 
existing behavior or public APIs.

https://github.com/apache/james-project/pull/3198

  was:
Context & Motivation

    While Apache James has adopted Project Reactor for modern, non-blocking 
I/O, the IMAP IDLE implementation still retained legacy synchronous primitives 
and fragile lifecycle management. Under real-world workloads—particularly with
  high event concurrency and unstable client connections (mobile networks, NAT 
expirations, abrupt client drops)—these gaps led to thread pool exhaustion, 
lingering ghost connections, and subtle protocol race conditions.

What PR #3198 Achieves

    This PR hardens the IMAP IDLE subsystem through targeted, 
backward-compatible improvements centered on three core architectural pillars:

    1. **Fully Non-Blocking Event Flow**:
       Migrates internal event synchronization from blocking primitives 
(`CountDownLatch::await`) to native reactive constructs (`Sinks.One`), ensuring 
Reactor and Netty worker threads are never held up waiting for handshake
  completions.

    2. **Defensive Lifecycle & Resource Management**:
       Guarantees deterministic cleanup across both happy paths and edge cases 
(unannounced client disconnects, mailbox deselection, and I/O write failures). 
Listener registrations and scheduled heartbeat tasks now cleanly self-heal
  and release session references immediately rather than relying on delayed 
garbage collection.

    3. **Strict Protocol Compliance & Network Robustness**:
       - Aligns Netty idle state tracking with RFC 2177, ensuring 
dead/half-open client connections are reliably detected even when outbound 
server heartbeats are actively running.
       - Eliminates protocol data races by ensuring clean response ordering 
between untagged mailbox updates and terminal tagged completion statuses.
       - Provides fault-tolerant handling of line delimiters and immediate 
buffer flushing to prevent artificial client handshake latency.

    ### Expected Impact
    Greatly improved stability under heavy mail delivery, lower heap footprint 
from eliminating zombie sessions, and cleaner server logs without breaking any 
existing behavior or public APIs.

https://github.com/apache/james-project/pull/3198


> Hardening IMAP IDLE: Eliminate blocking synchronization, improve lifecycle 
> resilience, and fix idle timeout handling
> --------------------------------------------------------------------------------------------------------------------
>
>                 Key: JAMES-4233
>                 URL: https://issues.apache.org/jira/browse/JAMES-4233
>             Project: James Server
>          Issue Type: Improvement
>          Components: IMAPServer
>    Affects Versions: master, 3.9.0
>            Reporter: ilya terskov
>            Priority: Minor
>
> h1. *Context & Motivation*
>     While Apache James has adopted Project Reactor for modern, non-blocking 
> I/O, the IMAP IDLE implementation still retained legacy synchronous 
> primitives and fragile lifecycle management. Under real-world 
> workloads—particularly with
>   high event concurrency and unstable client connections (mobile networks, 
> NAT expirations, abrupt client drops)—these gaps led to thread pool 
> exhaustion, lingering ghost connections, and subtle protocol race conditions.
> h1. *What PR #3198 Achieves*
>     This PR hardens the IMAP IDLE subsystem through targeted, 
> backward-compatible improvements centered on three core architectural pillars:
>     1. **Fully Non-Blocking Event Flow**:
>        Migrates internal event synchronization from blocking primitives 
> (`CountDownLatch::await`) to native reactive constructs (`Sinks.One`), 
> ensuring Reactor and Netty worker threads are never held up waiting for 
> handshake
>   completions.
>     2. **Defensive Lifecycle & Resource Management**:
>        Guarantees deterministic cleanup across both happy paths and edge 
> cases (unannounced client disconnects, mailbox deselection, and I/O write 
> failures). Listener registrations and scheduled heartbeat tasks now cleanly 
> self-heal
>   and release session references immediately rather than relying on delayed 
> garbage collection.
>     3. **Strict Protocol Compliance & Network Robustness**:
>        - Aligns Netty idle state tracking with RFC 2177, ensuring 
> dead/half-open client connections are reliably detected even when outbound 
> server heartbeats are actively running.
>        - Eliminates protocol data races by ensuring clean response ordering 
> between untagged mailbox updates and terminal tagged completion statuses.
>        - Provides fault-tolerant handling of line delimiters and immediate 
> buffer flushing to prevent artificial client handshake latency.
>     ### Expected Impact
>     Greatly improved stability under heavy mail delivery, lower heap 
> footprint from eliminating zombie sessions, and cleaner server logs without 
> breaking any existing behavior or public APIs.
> https://github.com/apache/james-project/pull/3198



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

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

Reply via email to