Skip to content

Give mail-send deadlines and cancellation protocol meaning #726

Closed
3 of 3 issues completed
Closed

Description

@bbottema

Simple-batch provider setup cleanup — accepted 8 November 2026

A simple batch can obtain a Transport from a supplied Jakarta Mail Session and then leave it unclosed if lifecycle-adapter setup fails before connection.

// nativeSession selects a custom provider with a service-registered lifecycle adapter.
try (Mailer mailer = mail.mailerBuilder(nativeSession).buildMailer()) {
    mailer.sync().sendMailsInSimpleBatch(List.of(email));
}

If that adapter's constructor, provider factory or createAbortAction(...) throws, close the acquired Transport before propagating the setup failure. Preserve that original failure and attach any secondary close failure as suppressed. A successful registration must remain active through transport cleanup, so cancellation keeps its existing reach during close.

Use a small local helper around abort registration without changing the batch send loop, provider discovery or the normal connection path. This completes the unreleased cancellation/lifecycle integration introduced by this feature; it adds no public API, configuration or released migration obligation. ADR 0015 owns the transport and cleanup order, with ADR 0007 retaining per-operation provider discovery.


Part of #722, step 3 (phase 2), following bounded async submission. Add total-send budgets and cancellation that reaches queued work, pool waits and actual SMTP I/O while retaining accepted, known-unsent and ambiguous outcomes. The accepted API direction is MailSend with getCompletion() and secondary requestCancellation(), without more send overloads. A cancellation request never recalls accepted mail. Preserve observer-after-cleanup ordering, lazy batches, caller-owned resources and truthful custom-mailer capability. First prove safe interruption through supported provider hooks; if Angus cannot provide it without reflection or global mutable state, define the necessary provider/upstream seam instead of advertising future-only cancellation. Follow the root API expansion and coding guides, add fault-boundary and pooled-concurrency tests, and document stopped background/bulk-mail jobs. Leave implementation for review before commit.

Provider gate — resolved

The accepted implementation uses managed Angus transports and supported socket factories to capture and abort sockets independently of the SMTP monitor, including connection setup and TLS. The released pool controls provide cancellable claims and lease-generation fencing. No upstream Angus PR or reflection is required. Unsupported integrations retain untimed sending with cooperative cancellation and reject a configured total deadline before connecting.

The following records the original gate, before that implementation was reviewed:

Queue controls are being implemented separately in #725. In-flight cancellation is not implemented yet: cancelling a CompletableFuture does not stop SMTP, and Angus SMTPTransport.close() waits behind a send holding the transport monitor. A late request can therefore still be followed by successful SMTP acceptance.

Before exposing MailSend, we need a provider-owned, monitor-independent abort hook covering connection setup and TLS as well as sending, bound to the current attempt so it cannot affect a reused pooled connection. Pool waiting/allocation must cooperate, and the terminal receipt must retain final acceptance or post-DATA uncertainty. Caller-owned providers and CustomMailer callbacks also need an honest supported/unsupported boundary.

The next decision is an upstream Angus/pool hook or a separately reviewed socket-owning provider integration. Socket-factory/custom-provider alternatives are not ruled out by the current characterization, but must preserve Session, TLS, proxy, and lease ownership semantics. The step's stop condition applies; no deadline/cancellation return-type change is exposed yet. The detailed continuation is recorded in step 3 of the root SMTP robustness plan.

Anonymous IPv6 proxy endpoints — accepted 2 November 2026

The library-owned managed Angus socket factory interprets the first colon in every SOCKS host as an inline-port separator:

.withProxyConfig(SocksProxyConfig.builder().withHost("::1").withPort(1081).build())

Preserve the complete IPv6 literal and selected port when creating an anonymous proxy connection. Keep existing raw hostname:inline-port interpretation, separate-port precedence, authenticated bridge routing and HTTP-proxy precedence. Supplied Sessions and custom factories retain their established authority. This corrects the managed connection implementation introduced by this unreleased feature, under ADR 0010, ADR 0017 and ADR 0038. Proxy-authentication failover policy is a separate unresolved question.

Sub-issues

Sub-issues

3 of 3 Issues completed
Loading 3 sub-issues

Activity

  1. added this to the 10.0.0 milestone on Sep 8, 2026
  2. self-assigned this
    on Sep 8, 2026
  3. moved this from In Progress to Blocked in Simple Java Mail 10.0.0on Sep 8, 2026
  4. bbottema commented on Sep 8, 2026

    @bbottema
    OwnerAuthor

    The supporting-library work is released:

    Existing APIs remain available. A pending claim can now leave the queue without disturbing another borrower, and its old control cannot revoke a handed-out resource.

    This issue remains open: Simple Java Mail has not been integrated with these APIs, and default Angus still lacks a safe built-in physical-abort adapter. The supported/unsupported transport boundary and truthful SMTP outcomes remain prerequisites for exposing the full mail-send cancellation API. No Simple Java Mail 9.x backport is included. Release narrative tracked in #722.

  5. moved this from Blocked to In Progress in Simple Java Mail 10.0.0on Sep 9, 2026
  6. 31 remaining items

  7. bbottema commented on Nov 2, 2026

    @bbottema
    OwnerAuthor
    try (Mailer mailer = mail.mailerBuilder()
            .withSMTPServer("relay.example.org", 25)
            .withProxyConfig(SocksProxyConfig.builder()
                .withHost("::1").withPort(1081).build())
            .buildMailer()) {
        mailer.sync().testConnection();
    }

    The owned managed Angus connection retains the complete typed anonymous IPv6 proxy endpoint. Private probes retain that resolved route too. Raw provider syntax, later raw Session edits, HTTP precedence and supplied Session/custom-factory authority keep their existing meanings. Logical proxy locks constrain the resolved remote destination, while literal raw Session locks retain their exact-property contract. The internal endpoint handoff adds no configuration key or provider SPI.

    Delivered on the unreleased 10.0.0 development branch in 1e08cf224, following ADR 0010, ADR 0017 and ADR 0038.

  8. moved this from Done to In Progress in Simple Java Mail 10.0.0on Nov 8, 2026
  9. bbottema commented on Nov 8, 2026

    @bbottema
    OwnerAuthor
    try (Mailer mailer = mail.mailerBuilder(nativeSession).buildMailer()) {
        mailer.sync().sendMailsInSimpleBatch(List.of(email));
    }

    The simple batch now closes its acquired Transport before a lifecycle-adapter setup failure reaches the caller. A secondary close failure stays suppressed on the original setup failure. Cancellation remains registered until ordinary transport cleanup has finished.

    Delivered on the unreleased 10.0.0 development branch in 22beeb61, with website guidance and shared documentation.

    ADR 0015 owns cleanup ordering, while ADR 0007 retains per-operation provider construction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions