Skip to content

[cronet_http] Add QUIC options and the remaining DNS options to CronetEngine.build - #2115

Open
brahim-guaali wants to merge 3 commits into
dart-lang:masterfrom
brahim-guaali:cronet-quic-and-dns-options
Open

brahim-guaali wants to merge 3 commits into
dart-lang:masterfrom
brahim-guaali:cronet-quic-and-dns-options

Conversation

@brahim-guaali

@brahim-guaali brahim-guaali commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

CronetEngine.build exposes most of Cronet's DnsOptions, but not two of them, and it exposes no QuicOptions. An app cannot, for example, allow TLS 0-RTT, change the QUIC handshake timeout, or choose how long a stale DNS answer waits for a fresh lookup.

New CronetEngine.build parameters:

Parameter Cronet option
preestablishConnectionsToStaleDnsResults DnsOptions.Builder.preestablishConnectionsToStaleDnsResults
freshLookupTimeout StaleDnsOptions.Builder.setFreshLookupTimeoutMillis
enableTlsZeroRtt QuicOptions.Builder.enableTlsZeroRtt
retryWithoutAltSvcOnQuicErrors QuicOptions.Builder.retryWithoutAltSvcOnQuicErrors
delayJobsWithAvailableSpdySession QuicOptions.Builder.delayJobsWithAvailableSpdySession
cryptoHandshakeTimeout QuicOptions.Builder.setCryptoHandshakeTimeoutSeconds (whole seconds)

All parameters are nullable and unset by default, so existing callers are unchanged.

The two DNS options were already in the generated bindings. The QUIC options needed org.chromium.net.QuicOptions added to tool/jnigen.dart and the bindings regenerated (dart run tool/jnigen.dart). CronetEngine.Builder.setQuicOptions was already bound.

Notes for review

  • 0-RTT early data can be replayed by an attacker. The doc comment says to enable it only when the server limits early data to safe requests.
  • cryptoHandshakeTimeout takes a Duration and sends whole seconds, which is what the Cronet API accepts. A value is rounded down, and one shorter than a second throws an ArgumentError instead of silently becoming zero.
  • The change follows the shape of [cronet_http] Add DNS configuration options to CronetEngine.build #1945: new parameters, doc comments, a CHANGELOG entry under 1.11.0-wip, and integration tests in cronet_engine_test.dart.

Testing

  • dart analyze is clean for lib/ and the example's integration tests.
  • New integration tests: quicOptions (all four options together, a single option, a handshake timeout rounded down, and one under a second rejected) and one dnsOptions test that sets every DNS option at once. They build an engine and make a request against a local server. They need a device or emulator.
  • Checked in an Android app on a Galaxy S10+ (Cronet 157 from Play Services) before the latest merge: an engine built with every new option set, together with the existing ones, builds without error and serves requests over HTTP/3.
  • The example's integration tests have not run. On Flutter 3.44.5 the example app fails to build, on a clean checkout of master as well (the kotlin-android plugin is applied on top of AGP 9). The repository's own cronet_http workflow is failing on master for the same reason, so the checks here can't pass until that is fixed.

@google-cla

google-cla Bot commented Nov 17, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for additional DNS options (preestablishConnectionsToStaleDnsResults, freshLookupTimeout) and QUIC options (enableTlsZeroRtt, retryWithoutAltSvcOnQuicErrors, delayJobsWithAvailableSpdySession, cryptoHandshakeTimeout) to CronetEngine.build, along with integration tests. Feedback is provided to add validation for cryptoHandshakeTimeout to ensure it is at least 1 second, as sub-second durations would otherwise be silently truncated to 0 and cause failures.

Comment on lines +486 to +491
if (cryptoHandshakeTimeout != null) {
quicOptionsBuilder
.setCryptoHandshakeTimeoutSeconds(
cryptoHandshakeTimeout.inSeconds)
?.release();
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Since cryptoHandshakeTimeout is specified as a Duration but Cronet's setCryptoHandshakeTimeoutSeconds only accepts whole seconds, any sub-second duration (e.g., Duration(milliseconds: 500)) will be silently truncated to 0 seconds. A handshake timeout of 0 or less is invalid and will likely cause immediate failures or unexpected behavior.

Consider adding a validation check to ensure that cryptoHandshakeTimeout is at least 1 second.

            if (cryptoHandshakeTimeout != null) {
              if (cryptoHandshakeTimeout.inSeconds <= 0) {
                throw ArgumentError.value(
                  cryptoHandshakeTimeout,
                  'cryptoHandshakeTimeout',
                  'Must be at least 1 second.',
                );
              }
              quicOptionsBuilder
                  .setCryptoHandshakeTimeoutSeconds(
                      cryptoHandshakeTimeout.inSeconds)
                  ?.release();
            }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. A cryptoHandshakeTimeout shorter than one second now throws an ArgumentError, and longer values are rounded down to whole seconds. Both are documented on the parameter and covered by two new integration tests.

@brahim-guaali
brahim-guaali force-pushed the cronet-quic-and-dns-options branch from 6b8dba9 to c5abfc6 Compare November 17, 2026 12:00
…tEngine.build

CronetEngine.build exposes most DnsOptions, but not preestablishing
connections to stale results or the fresh lookup timeout, and it exposes no
QuicOptions at all, so 0-RTT, the retry without Alt-Svc on QUIC errors, the
handshake timeout and the HTTP/2 session delay cannot be set from Dart.

Add preestablishConnectionsToStaleDnsResults and freshLookupTimeout to the
DNS options, and enableTlsZeroRtt, retryWithoutAltSvcOnQuicErrors,
delayJobsWithAvailableSpdySession and cryptoHandshakeTimeout as QUIC options.
The first two DNS options were already bound; the QUIC options come from
adding org.chromium.net.QuicOptions to the generated JNI bindings.
@brahim-guaali
brahim-guaali force-pushed the cronet-quic-and-dns-options branch from c5abfc6 to ab8eee5 Compare November 17, 2026 12:30
…cond

The Cronet option only takes whole seconds, so a shorter Duration used to
become zero. It now throws an ArgumentError, and a longer value is rounded
down. Both are documented and covered by integration tests.
@brahim-guaali
brahim-guaali marked this pull request as ready for review November 20, 2026 11:31
Keep both changelog entries and regenerate the JNI bindings with jnigen 1.1.0
so they include QuicOptions on top of upstream regenerated output.
@brahim-guaali
brahim-guaali force-pushed the cronet-quic-and-dns-options branch from abe3789 to c274df1 Compare November 20, 2026 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant