Skip to content

http: proxying 102s. - #19023

Merged
alyssawilk merged 6 commits into
envoyproxy:mainfrom
alyssawilk:102
Nov 17, 2021
Merged

alyssawilk merged 6 commits into
envoyproxy:mainfrom
alyssawilk:102

Conversation

@alyssawilk

Copy link
Copy Markdown
Contributor

Proxying 102s from upstream

Risk Level: Low (minor refactor)
Testing: new integration test
Docs Changes: n/a
Release Notes: inline
Runtime guard: envoy.reloadable_features.proxy_102
Fixes #18844

Signed-off-by: Alyssa Wilk <[email protected]>
Signed-off-by: Alyssa Wilk <[email protected]>
Signed-off-by: Alyssa Wilk <[email protected]>
@alyssawilk alyssawilk self-assigned this Nov 16, 2021
Signed-off-by: Alyssa Wilk <[email protected]>
@alyssawilk alyssawilk assigned snowp and unassigned alyssawilk Nov 16, 2021
@alyssawilk

Copy link
Copy Markdown
Contributor Author

cc @RyanTheOptimist @DavidSchinazi now with 103s :-)

@RyanTheOptimist RyanTheOptimist left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Woo hoo! Looks awesome. One small question.

testEnvoyProxying1xx(false, false, true);
}

TEST_P(ProtocolIntegrationTest, EnvoyProxying102) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we also have a 103 test here?

DavidSchinazi
DavidSchinazi previously approved these changes Nov 16, 2021
Comment thread docs/root/version_history/current.rst Outdated
* bandwidth_limit: added :ref:`bandwidth limit stats <config_http_filters_bandwidth_limit>` *request_enforced* and *response_enforced*.
* config: the log message for "gRPC config stream closed" now uses the most recent error message, and reports seconds instead of milliseconds for how long the most recent status has been received.
* dns: now respecting the returned DNS TTL for resolved hosts, rather than always relying on the hard-coded :ref:`dns_refresh_rate. <envoy_v3_api_field_config.cluster.v3.Cluster.dns_refresh_rate>` This behavior can be temporarily reverted by setting the runtime guard ``envoy.reloadable_features.use_dns_ttl`` to false.
* http: envoy will now proxy 102 and 103 headers from upstream, though as with 100s only the first 1xx response headers will be sent. This behavioral change by can temporarily revertd by setting runtime guard ``envoy.reloadable_features.proxy_102_103`` to false.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
* http: envoy will now proxy 102 and 103 headers from upstream, though as with 100s only the first 1xx response headers will be sent. This behavioral change by can temporarily revertd by setting runtime guard ``envoy.reloadable_features.proxy_102_103`` to false.
* http: envoy will now proxy 102 and 103 headers from upstream, though as with 100s only the first 1xx response headers will be sent. This behavioral change by can temporarily reverted by setting runtime guard ``envoy.reloadable_features.proxy_102_103`` to false.

Signed-off-by: Alyssa Wilk <[email protected]>
Signed-off-by: Alyssa Wilk <[email protected]>

@snowp snowp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, thanks!

@alyssawilk
alyssawilk merged commit 93cdfce into envoyproxy:main Nov 17, 2021
@alyssawilk
alyssawilk deleted the 102 branch August 4, 2022 01:13
RyanTheOptimist pushed a commit that referenced this pull request Jul 8, 2024
Proxying 104s from upstream.

`104 Upload Resumption Supported` is introduced in
[`draft-ietf-httpbis-resumable-upload`](https://datatracker.ietf.org/doc/draft-ietf-httpbis-resumable-upload/)
spec.

Continuation of the discussion in
#19044
Modeled after: #19023

Risk Level: Low (minor refactor)
Testing: new integration test
Docs Changes: N/A

Release Notes: 

> http: envoy will now proxy 104 headers from upstream, though as with
100s only the first 1xx response headers will be sent. This behavior can
be temporarily reverted by setting runtime guard
`envoy.reloadable_features.proxy_104` to false. 104 headers are
designated by [ietf's draft-ietf-httpbis-resumable-upload
rfc](https://datatracker.ietf.org/doc/draft-ietf-httpbis-resumable-upload/).

Runtime guard: 
> `envoy.reloadable_features.proxy_104`

---------

Signed-off-by: Neal Soni <[email protected]>
alco pushed a commit to neondatabase/electric that referenced this pull request Apr 13, 2026
…meouts (#4106)

## Summary

- Sends periodic HTTP `102 Processing` informational responses during
long-poll holds to prevent network middleboxes (Cloudflare edge nodes on
long paths to origin) from dropping idle connections (522 errors)
- Zero client changes required — fully backwards compatible with
existing TypeScript and Elixir clients
- All 51 existing API tests pass with no modifications

## Problem

Long-poll requests to `/v1/shape?live=true` hold connections idle for up
to 20 seconds inside `hold_until_change`. During this time, no bytes
flow on the wire. Middleboxes on long network paths (e.g., Cloudflare
colos BAH, HKG hitting ALB in us-east-1) can drop these connections,
causing sporadic 522 errors.

## Approach

Uses `Plug.Conn.inform(conn, 102)` to send HTTP 1xx informational
responses every 5–15 seconds during the hold. These responses:

1. **Send bytes on the wire** — keeps middlebox connections alive
2. **Don't commit the final response** — headers and status code are
sent only after the hold resolves, with correct values
3. **Are invisible to HTTP clients** — `fetch()`, Req, and all standard
HTTP clients transparently ignore 1xx responses per RFC 9110 §15.2
4. **Preserve CDN request collapsing** — since 1xx responses are not
final responses, the CDN's coalescing window remains open for the full
hold duration (see CDN section below)

### Implementation details

- A `:timer.send_interval` starts when a live non-SSE request enters the
Plug path (`serve_shape_response/2` or `serve_shape_log/2`)
- A `register_before_send` callback cancels the timer and flushes stale
messages when the response is sent
- The keepalive callback is stored as a closure (`on_keepalive`) on the
`Request` struct, keeping `Plug.Conn` out of the domain struct
- `hold_until_change` is split into two functions: the outer sets up a
`Process.send_after` timeout timer (replacing `receive...after` which
would reset on keepalive re-entry), the inner `do_hold_until_change`
handles the receive loop with a new `:long_poll_keepalive` clause
- Keepalive interval is `div(long_poll_timeout, 4)` clamped to 5–15
seconds

## Alternatives considered

### Chunked transfer encoding with whitespace keepalive bytes

Send `Transfer-Encoding: chunked` immediately and emit `" "` (space)
chunks as keepalive during the hold, then send the real JSON payload as
the final chunk.

**Rejected for two reasons:**

1. **Breaks backwards compatibility.** HTTP headers are committed when
chunked encoding starts, before the hold resolves. The `electric-offset`
header would be stale when new data arrives during the hold. This
requires a TypeScript client change (using body-based offset instead of
header-based) to avoid an infinite re-fetch loop — breaking old clients
on the new server.

2. **Breaks CDN request collapsing.** Live long-poll responses are
cacheable (`Cache-Control: public, max-age=5,
stale-while-revalidate=5`). With the current non-chunked approach, CDNs
like Cloudflare hold the coalescing window open for the full hold
duration — multiple clients requesting the same shape+offset are
collapsed into one origin request. Starting a chunked response
immediately closes this window on Cloudflare and CloudFront because the
response is already "in flight." With 102, the coalescing window stays
open since 1xx responses are not final responses.

### Stream.resource pattern (modeled on existing SSE keepalive)

Replace `hold_until_change` entirely with a `Stream.resource` that emits
keepalive chunks and data chunks as a streaming response body.

**Rejected because** it changes the response semantics: the `Response`
struct fields (`offset`, `up_to_date`, `status`) are frozen at stream
creation time rather than set after the hold resolves. This broke 11
existing tests and required changing error behavior (shape rotation,
out-of-bounds, stack failure all became 200 with empty body instead of
their proper status codes). Also has the same CDN collapsing and
backwards-compatibility issues as the chunked approach.

### Shorter long-poll timeout

Reduce `long_poll_timeout` to well under the middlebox timeout.

**Rejected because** it doubles the request rate for idle shapes without
solving the root cause.

## On HTTP 102 Processing

`102 Processing` was defined in RFC 2518 (WebDAV, 1999) specifically for
preventing client timeouts on long-running requests — the exact use case
here. It was removed in RFC 4918 (2007) with the stated reason: **"due
to lack of implementation"** — not because it was harmful or
architecturally unsound.

MDN labels 102 as "deprecated," but this is an editorial judgment, not a
standards-body action. No RFC has ever formally deprecated 102. The
status is more accurately described as "no longer defined by any active
RFC" — a state shared by many widely-used status codes (429 Too Many
Requests was also defined outside RFC 9110's predecessor until
recently).

### Why it's safe to use

- **RFC 9110 §15.2 requires** all HTTP/1.1+ clients to parse unknown 1xx
responses and allows ignoring them — sending 102 cannot break
spec-compliant implementations
- **RFC 9110 §15.1 explicitly acknowledges** status codes "outside the
scope of this specification" as legitimate, provided they are
IANA-registered
- **102 is permanently registered** in the [IANA HTTP Status Code
Registry](https://www.iana.org/assignments/http-status-codes) with no
deregistration attempts
- **Cloudflare explicitly supports and recommends it** for keepalive:
["If Cloudflare receives a 102 Processing response, it expects a final
response within 120
seconds"](https://developers.cloudflare.com/support/troubleshooting/http-status-codes/1xx-informational/)
- **All major proxies forward it**: nginx, HAProxy, Envoy (since
[envoyproxy/envoy#19023](envoyproxy/envoy#19023))
- **HTTP/2 (RFC 9113 §8.8.5)** explicitly handles 1xx informational
responses including 102
- **Bandit supports it** natively via `Plug.Conn.inform/2`; **Node.js**
has `response.writeProcessing()` since v10; **Go** added 1xx support in
Go 1.19
- **No other 1xx code fits**: `100 Continue` is for request bodies, `103
Early Hints` is for resource preloading and would confuse browsers

### Known limitations

- **Go's `net/http`** has a default limit of 5 consecutive 1xx
responses. Our 3–4 responses per hold (at 5s intervals over 20s) are
within this limit.
- **AWS ALB** may silently drop 1xx responses — this is harmless since
ALB's idle timeout (default 60s, configurable up to 4000s) already
exceeds typical long-poll durations.
- **Spring Framework 7.0** deprecated the `HttpStatus.PROCESSING` enum
constant. This is the only major framework taking action, and it's the
constant, not the protocol behavior.

## CDN request collapsing

Electric's live long-poll responses are cacheable (`Cache-Control:
public, max-age=5, stale-while-revalidate=5`), which enables CDN request
collapsing — multiple clients requesting the same shape+offset are
collapsed into a single origin request.

The 102 approach preserves this because 1xx informational responses are
not final responses. The CDN continues to hold the coalescing window
open until the final 200 arrives. This is significant under high
concurrency where many clients subscribe to the same shape.

By contrast, the alternative chunked-whitespace approach would close the
coalescing window immediately by committing a 200 response before the
hold resolves.

## Test plan

- [x] All 51 existing `api_test.exs` tests pass with no modifications
- [x] All 311 TypeScript client unit tests pass with no modifications
- [ ] Integration test with real HTTP server verifying 102 responses
arrive on the wire
- [ ] Manual verification against Cloudflare-fronted deployment

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
Co-authored-by: Ilia Borovitinov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pass through HTTP status 102 processing

4 participants