v0.41.2
This commit is contained in:
1 parent
934d748ea2
commit
8d15429560
13 files changed
+171
-17
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
# RustProxy source and documentation maintenance
|
# RustProxy source and documentation maintenance
|
||||||
|
|
||||||
Current source version: **0.41.1**. The Cargo package and binary are named `rust-proxy`.
|
Current source version: **0.41.2**. The Cargo package and binary are named `rust-proxy`.
|
||||||
|
|
||||||
Before editing, read [README.md](README.md), the relevant [documentation guide](docs/README.md) and the actual code and tests. Historical release experiments are not current specifications. Use the bundled `src/admin/openapi.json` for API routes and payloads; the source implementation is authoritative for runtime behavior.
|
Before editing, read [README.md](README.md), the relevant [documentation guide](docs/README.md) and the actual code and tests. Historical release experiments are not current specifications. Use the bundled `src/admin/openapi.json` for API routes and payloads; the source implementation is authoritative for runtime behavior.
|
||||||
|
|
||||||
|
|||||||
+5
-2
@@ -2,13 +2,16 @@
|
|||||||
|
|
||||||
Release history focused on **features, settings, default behavior, compatibility and fixes**. Changes to internal code structure and preliminary performance experiments are intentionally omitted. Historical descriptions reflect their respective releases; consult the current documentation for the settings available in the latest release.
|
Release history focused on **features, settings, default behavior, compatibility and fixes**. Changes to internal code structure and preliminary performance experiments are intentionally omitted. Historical descriptions reflect their respective releases; consult the current documentation for the settings available in the latest release.
|
||||||
|
|
||||||
|
## 0.41.2 — QUIC keep-alive for long HTTP/3 requests
|
||||||
|
|
||||||
|
- **HTTP/3 keep-alive:** the HTTP/3 settings of a TLS listener gain `keep_alive_interval` (seconds between QUIC PING frames, `0` = off, default) and `keep_alive_mode`. Without keep-alive a request that sends nothing for longer than the QUIC idle timeout (default 10 s) — long polling, ActiveSync `Ping`, SSE, a slow upstream before its headers — was cut off together with its connection (`http3_accept_error: Timeout`), which mobile NATs make worse. In `active_requests` mode (default) PINGs keep connections alive and RustProxy closes a connection with GOAWAY once it had no request in progress for `max_idle_timeout`, so idle browser connections are still reclaimed; `always` keeps every connection until the client closes it. The interval must be shorter than the idle timeout (unless that is `0`). Applies to new QUIC connections without a restart. See [QUIC keep-alive](docs/TRANSPORT.md#quic-keep-alive-long-requests-over-http3).
|
||||||
|
- **Panel:** **Settings → HTTP/3** shows *QUIC keep-alive* and *QUIC keep-alive mode*; English and Polish texts added. API schema updated.
|
||||||
|
|
||||||
## 0.41.1 — Stored logs: rotation fix, per-host log files and rebuilt explorer
|
## 0.41.1 — Stored logs: rotation fix, per-host log files and rebuilt explorer
|
||||||
|
|
||||||
- **Logging — rotation fix:** access logs (shared and per-Vhost) and the error log now notice external rotation (logrotate `create`, `mv`, `rm`) about once per second and reopen the configured path. Up to 0.41.0 RustProxy kept writing into the renamed file until a restart, so after `compress` those records were lost and the stored-log reader showed an old rotation (e.g. `.10.gz`) as the newest data. No `postrotate` or `copytruncate` is needed; a sample logrotate policy is in [Logs](docs/LOGS.md#per-site-files-and-rotation).
|
- **Logging — rotation fix:** access logs (shared and per-Vhost) and the error log now notice external rotation (logrotate `create`, `mv`, `rm`) about once per second and reopen the configured path. Up to 0.41.0 RustProxy kept writing into the renamed file until a restart, so after `compress` those records were lost and the stored-log reader showed an old rotation (e.g. `.10.gz`) as the newest data. No `postrotate` or `copytruncate` is needed; a sample logrotate policy is in [Logs](docs/LOGS.md#per-site-files-and-rotation).
|
||||||
- **Logging — redirect and 404 hosts:** with per-Vhost access logs, requests answered by a redirect host go to `<id>.redirect.jsonl` and requests answered by a local 404 host to `<id>.host404.jsonl` instead of `_unmatched.jsonl`; their records carry `redirect_host` / `local_host` (omitted otherwise, also available as custom format fields). They are not counted as Vhost traffic.
|
- **Logging — redirect and 404 hosts:** with per-Vhost access logs, requests answered by a redirect host go to `<id>.redirect.jsonl` and requests answered by a local 404 host to `<id>.host404.jsonl` instead of `_unmatched.jsonl`; their records carry `redirect_host` / `local_host` (omitted otherwise, also available as custom format fields). They are not counted as Vhost traffic.
|
||||||
- **Stored logs — rebuilt explorer:** sources are grouped per log (Vhosts, Redirect hosts, 404 hosts, Other traffic, shared access log, error log) with a separate **File** picker (current file, `.1`, `.2.gz`, …). Rotations are ordered by number instead of modification time and uncompressed rotations (`.1`) are included; a log is read newest-first so the newest records are always complete, and the status line shows the time range, the files read and how to reach older ones. New **Period** filter (`since_ms`, stops before older rotations), status/protocol-error chips, **← Newer / Older →** paging, an inline search-syntax panel with tap-to-use examples (the old popover opened off-screen on phones), source names instead of file ids, status-coloured cards on phones. API: `/api/file-logs` sources gain `rotation`, `scope` and `site`; queries accept `since_ms` and return `files`, `files_skipped`, `stopped_at_period`, `newest_ms` and `oldest_ms`; `consolidate_vhosts` now merges any log's rotations.
|
- **Stored logs — rebuilt explorer:** sources are grouped per log (Vhosts, Redirect hosts, 404 hosts, Other traffic, shared access log, error log) with a separate **File** picker (current file, `.1`, `.2.gz`, …). Rotations are ordered by number instead of modification time and uncompressed rotations (`.1`) are included; a log is read newest-first so the newest records are always complete, and the status line shows the time range, the files read and how to reach older ones. New **Period** filter (`since_ms`, stops before older rotations), status/protocol-error chips, **← Newer / Older →** paging, an inline search-syntax panel with tap-to-use examples (the old popover opened off-screen on phones), source names instead of file ids, status-coloured cards on phones. API: `/api/file-logs` sources gain `rotation`, `scope` and `site`; queries accept `since_ms` and return `files`, `files_skipped`, `stopped_at_period`, `newest_ms` and `oldest_ms`; `consolidate_vhosts` now merges any log's rotations.
|
||||||
- **Upgrade note:** if logs are rotated externally, restart the service once after upgrading — a process older than 0.41.1 keeps writing into the rotated file until it restarts.
|
|
||||||
- **Compatibility:** configuration format unchanged. Access-log records gain `redirect_host` / `local_host` only for requests answered by redirect or local 404 hosts. Redirect/404 traffic moves from `_unmatched.jsonl` to its own files when per-Vhost logs are enabled.
|
|
||||||
|
|
||||||
## 0.41.0 — Conditional routing: request conditions and whole-host rules
|
## 0.41.0 — Conditional routing: request conditions and whole-host rules
|
||||||
|
|
||||||
|
|||||||
Generated
+1
-1
@@ -1914,7 +1914,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rust-proxy"
|
name = "rust-proxy"
|
||||||
version = "0.41.1"
|
version = "0.41.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"arc-swap",
|
"arc-swap",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "rust-proxy"
|
name = "rust-proxy"
|
||||||
version = "0.41.1"
|
version = "0.41.2"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
rust-version = "1.99.1"
|
rust-version = "1.99.1"
|
||||||
description = "RustProxy - independent reverse proxy with local administration"
|
description = "RustProxy - independent reverse proxy with local administration"
|
||||||
|
|||||||
+1
-1
@@ -21,7 +21,7 @@ RustProxy is a single service that combines a reverse proxy, a static/PHP web se
|
|||||||
|
|
||||||
## Frontends and TLS
|
## Frontends and TLS
|
||||||
|
|
||||||
- HTTP/1.1, HTTPS with HTTP/2, optional HTTP/3 (QUIC) with `Alt-Svc` management and configurable UDP buffers.
|
- HTTP/1.1, HTTPS with HTTP/2, optional HTTP/3 (QUIC) with `Alt-Svc` management, configurable UDP buffers and QUIC keep-alive for long requests (only while a request is in progress, or always).
|
||||||
- Named listeners with per-listener protocols; Vhosts bind to listener IDs.
|
- Named listeners with per-listener protocols; Vhosts bind to listener IDs.
|
||||||
- TLS 1.2/1.3 policy with cipher-suite allowlist and per-Vhost overrides.
|
- TLS 1.2/1.3 policy with cipher-suite allowlist and per-Vhost overrides.
|
||||||
- Optional hybrid post-quantum key exchange (X25519MLKEM768).
|
- Optional hybrid post-quantum key exchange (X25519MLKEM768).
|
||||||
|
|||||||
+25
-1
@@ -17,9 +17,33 @@ Transport settings attach to **named listeners**, and a Vhost must select the ap
|
|||||||
|
|
||||||
- **Immediately after a successful panel save:** H2/H1 TLS responses use the saved `alt_svc_max_age` (`Alt-Svc`), provided a matching UDP listener was actually bound at startup. Origin `Alt-Svc` never passes through. The value `0` publishes `ma=0`.
|
- **Immediately after a successful panel save:** H2/H1 TLS responses use the saved `alt_svc_max_age` (`Alt-Svc`), provided a matching UDP listener was actually bound at startup. Origin `Alt-Svc` never passes through. The value `0` publishes `ma=0`.
|
||||||
- **Disabling H3 on a Vhost or an existing listener:** new H1/H2 responses publish `Alt-Svc: clear` to remove the browser's cached alternative service. A browser may keep an established QUIC connection until it closes; `clear` does not forcibly terminate it.
|
- **Disabling H3 on a Vhost or an existing listener:** new H1/H2 responses publish `Alt-Svc: clear` to remove the browser's cached alternative service. A browser may keep an established QUIC connection until it closes; `clear` does not forcibly terminate it.
|
||||||
- **For new QUIC connections only:** updates to `max_concurrent_bidistream`, `max_concurrent_unistream`, `max_idle_timeout` and reductions to `max_concurrent_connections` are applied without restart. Existing QUIC connections keep their negotiated limits. If no existing UDP socket matches the saved listener address, no H3 is advertised or accepted on the old address.
|
- **For new QUIC connections only:** updates to `max_concurrent_bidistream`, `max_concurrent_unistream`, `max_idle_timeout`, `keep_alive_interval`, `keep_alive_mode` and reductions to `max_concurrent_connections` are applied without restart. Existing QUIC connections keep their negotiated limits. If no existing UDP socket matches the saved listener address, no H3 is advertised or accepted on the old address.
|
||||||
- **Restart needed:** UDP listener enable/disable, changing IP/port/TLS properties, UDP socket buffer sizes, changes to H1/H2 listener settings and increasing `max_concurrent_connections` above the startup bound. The live listener status continues to show `restart_required` for these cases. After a restart, the new connection cap can take effect.
|
- **Restart needed:** UDP listener enable/disable, changing IP/port/TLS properties, UDP socket buffer sizes, changes to H1/H2 listener settings and increasing `max_concurrent_connections` above the startup bound. The live listener status continues to show `restart_required` for these cases. After a restart, the new connection cap can take effect.
|
||||||
|
|
||||||
|
### QUIC keep-alive (long requests over HTTP/3)
|
||||||
|
|
||||||
|
A QUIC connection is closed when no packet crosses it for `max_idle_timeout` (default 10 s; the effective
|
||||||
|
value is the lower of the client's and the server's). A request that is legitimately silent for longer —
|
||||||
|
long polling, ActiveSync `Ping`, Server-Sent Events, a slow upstream before its response headers — is then
|
||||||
|
cut off together with the connection, and mobile NATs drop idle UDP mappings even sooner. HTTP/2 over TCP
|
||||||
|
does not have this problem.
|
||||||
|
|
||||||
|
| Parameter | Default | Accepted values | Meaning |
|
||||||
|
|---|---:|---|---|
|
||||||
|
| `keep_alive_interval` | `0` (off) | 0–3600 s, shorter than `max_idle_timeout` unless that is `0` | Seconds between QUIC PING frames sent by RustProxy |
|
||||||
|
| `keep_alive_mode` | `active_requests` | `active_requests`, `always` | When the PINGs keep a connection open |
|
||||||
|
|
||||||
|
- `active_requests` (recommended): PINGs keep every connection alive at the transport level, and RustProxy
|
||||||
|
itself closes a connection (HTTP/3 GOAWAY) once it has had no request in progress for `max_idle_timeout`.
|
||||||
|
Idle browser connections therefore still close as before, while connections with a long request stay open.
|
||||||
|
- `always`: every connection is kept alive until the client closes it. Use only with a sufficient
|
||||||
|
`max_concurrent_connections`, because idle connections are no longer reclaimed by the server.
|
||||||
|
|
||||||
|
Suggested values for sites with long requests: `max_idle_timeout` 30 s and `keep_alive_interval` 15 s (below
|
||||||
|
typical mobile NAT UDP timeouts). The settings apply to new QUIC connections without a restart. The response
|
||||||
|
header/read timeouts of the Vhost still apply. For ActiveSync, disabling HTTP/3 on the Vhost remains the most
|
||||||
|
robust choice.
|
||||||
|
|
||||||
### QUIC UDP socket buffers
|
### QUIC UDP socket buffers
|
||||||
|
|
||||||
The HTTP/3 settings of each TLS listener include:
|
The HTTP/3 settings of each TLS listener include:
|
||||||
|
|||||||
+6
-1
@@ -632,8 +632,13 @@
|
|||||||
"h3_max_concurrent_bidistream": "Bidirectional streams per connection",
|
"h3_max_concurrent_bidistream": "Bidirectional streams per connection",
|
||||||
"h3_max_concurrent_unistream": "Unidirectional streams per connection",
|
"h3_max_concurrent_unistream": "Unidirectional streams per connection",
|
||||||
"h3_max_idle_timeout": "QUIC idle timeout (s; 0 = unlimited)",
|
"h3_max_idle_timeout": "QUIC idle timeout (s; 0 = unlimited)",
|
||||||
|
"h3_keep_alive_interval": "QUIC keep-alive (s; 0 = off)",
|
||||||
|
"h3_keep_alive_mode": "QUIC keep-alive mode",
|
||||||
|
"h3KeepAliveActiveRequests": "only during active requests",
|
||||||
|
"h3KeepAliveAlways": "always",
|
||||||
|
"h3KeepAliveTooLong": "Keep-alive must be shorter than the QUIC idle timeout.",
|
||||||
"h3Help": "HTTP/3 requires TLS. Keep TCP plus the same UDP port available; HTTP/1.1 and HTTP/2 remain. Zero disables the local QUIC idle timeout. Changes require restart.",
|
"h3Help": "HTTP/3 requires TLS. Keep TCP plus the same UDP port available; HTTP/1.1 and HTTP/2 remain. Zero disables the local QUIC idle timeout. Changes require restart.",
|
||||||
"h3TuningHelp": "Alt-Svc updates immediately; stream and idle limits apply to new QUIC connections. Changing UDP receive/send socket buffers (default 4 MiB each) or listener bindings needs a restart. On Linux, socket buffers may be capped by net.core.rmem_max / wmem_max.",
|
"h3TuningHelp": "Alt-Svc updates immediately; stream and idle limits apply to new QUIC connections. Changing UDP receive/send socket buffers (default 4 MiB each) or listener bindings needs a restart. On Linux, socket buffers may be capped by net.core.rmem_max / wmem_max. Keep-alive sends QUIC PINGs so long requests (long polling, ActiveSync Ping, SSE) are not cut by the idle timeout or NATs; in 'only during active requests' mode, connections without requests are still closed after the idle timeout. Suggested: idle timeout 30 s, keep-alive 15 s.",
|
||||||
"h3Requests": "HTTP/3 requests",
|
"h3Requests": "HTTP/3 requests",
|
||||||
"certImport": "Import certificate",
|
"certImport": "Import certificate",
|
||||||
"certImportSave": "Import and save in library",
|
"certImportSave": "Import and save in library",
|
||||||
|
|||||||
+6
-1
@@ -632,8 +632,13 @@
|
|||||||
"h3_max_concurrent_bidistream": "Strumienie dwukierunkowe na połączenie",
|
"h3_max_concurrent_bidistream": "Strumienie dwukierunkowe na połączenie",
|
||||||
"h3_max_concurrent_unistream": "Strumienie jednokierunkowe na połączenie",
|
"h3_max_concurrent_unistream": "Strumienie jednokierunkowe na połączenie",
|
||||||
"h3_max_idle_timeout": "Bezczynność QUIC (s; 0 = bez limitu)",
|
"h3_max_idle_timeout": "Bezczynność QUIC (s; 0 = bez limitu)",
|
||||||
|
"h3_keep_alive_interval": "Podtrzymanie QUIC (s; 0 = wyłączone)",
|
||||||
|
"h3_keep_alive_mode": "Tryb podtrzymania QUIC",
|
||||||
|
"h3KeepAliveActiveRequests": "tylko podczas aktywnych żądań",
|
||||||
|
"h3KeepAliveAlways": "zawsze",
|
||||||
|
"h3KeepAliveTooLong": "Podtrzymanie musi być krótsze niż bezczynność QUIC.",
|
||||||
"h3Help": "HTTP/3 wymaga TLS. Udostępnij TCP i UDP na tym samym porcie; HTTP/1.1 i HTTP/2 pozostają. Zero wyłącza lokalny timeout QUIC. Zmiana wymaga restartu.",
|
"h3Help": "HTTP/3 wymaga TLS. Udostępnij TCP i UDP na tym samym porcie; HTTP/1.1 i HTTP/2 pozostają. Zero wyłącza lokalny timeout QUIC. Zmiana wymaga restartu.",
|
||||||
"h3TuningHelp": "Alt-Svc działa natychmiast; limity strumieni i bezczynności dotyczą nowych połączeń QUIC. Zmiana buforów UDP (domyślnie po 4 MiB) lub adresów listenerów wymaga restartu. Linux może ograniczać rozmiar przez net.core.rmem_max / wmem_max.",
|
"h3TuningHelp": "Alt-Svc działa natychmiast; limity strumieni i bezczynności dotyczą nowych połączeń QUIC. Zmiana buforów UDP (domyślnie po 4 MiB) lub adresów listenerów wymaga restartu. Linux może ograniczać rozmiar przez net.core.rmem_max / wmem_max. Podtrzymanie wysyła pakiety PING QUIC, aby długie żądania (long polling, ActiveSync Ping, SSE) nie były zrywane po czasie bezczynności ani przez NAT; w trybie „tylko podczas aktywnych żądań” połączenia bez żądań są zamykane po czasie bezczynności. Zalecane np. bezczynność 30 s i podtrzymanie 15 s.",
|
||||||
"h3Requests": "Żądania HTTP/3",
|
"h3Requests": "Żądania HTTP/3",
|
||||||
"certImport": "Importuj certyfikat",
|
"certImport": "Importuj certyfikat",
|
||||||
"certImportSave": "Importuj i zapisz w bibliotece",
|
"certImportSave": "Importuj i zapisz w bibliotece",
|
||||||
|
|||||||
+18
-1
@@ -8460,6 +8460,23 @@
|
|||||||
"maximum": 86400,
|
"maximum": 86400,
|
||||||
"default": 10
|
"default": 10
|
||||||
},
|
},
|
||||||
|
"keep_alive_interval": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int64",
|
||||||
|
"minimum": 0,
|
||||||
|
"maximum": 3600,
|
||||||
|
"default": 0,
|
||||||
|
"description": "Seconds between QUIC keep-alive PINGs; 0 disables. Must be shorter than max_idle_timeout (unless that is 0). Applies to new QUIC connections."
|
||||||
|
},
|
||||||
|
"keep_alive_mode": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"active_requests",
|
||||||
|
"always"
|
||||||
|
],
|
||||||
|
"default": "active_requests",
|
||||||
|
"description": "active_requests: PINGs keep connections with requests in progress alive; connections without requests are closed after max_idle_timeout. always: every connection is kept alive."
|
||||||
|
},
|
||||||
"udp_receive_buffer_bytes": {
|
"udp_receive_buffer_bytes": {
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"minimum": 0,
|
"minimum": 0,
|
||||||
@@ -16587,4 +16604,4 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"tags": []
|
"tags": []
|
||||||
}
|
}
|
||||||
@@ -86,21 +86,22 @@
|
|||||||
};
|
};
|
||||||
return { read, sync };
|
return { read, sync };
|
||||||
}
|
}
|
||||||
const h3Defaults = { alt_svc_max_age: 3600, max_concurrent_connections: 512, max_concurrent_bidistream: 100, max_concurrent_unistream: 100, max_idle_timeout: 10, udp_receive_buffer_bytes: 4194304, udp_send_buffer_bytes: 4194304 };
|
const h3Defaults = { alt_svc_max_age: 3600, max_concurrent_connections: 512, max_concurrent_bidistream: 100, max_concurrent_unistream: 100, max_idle_timeout: 10, keep_alive_interval: 0, keep_alive_mode: "active_requests", udp_receive_buffer_bytes: 4194304, udp_send_buffer_bytes: 4194304 };
|
||||||
function http3SettingsControls(parent, binding) {
|
function http3SettingsControls(parent, binding) {
|
||||||
const box = el("div", undefined, "h3-editor vh-wide"); parent.append(box);
|
const box = el("div", undefined, "h3-editor vh-wide"); parent.append(box);
|
||||||
const grid = el("div", undefined, "vh-grid"); box.append(grid); const inputs = {};
|
const grid = el("div", undefined, "vh-grid"); box.append(grid); const inputs = {};
|
||||||
for (const [name, min, max] of [["alt_svc_max_age", 0, 604800], ["max_concurrent_connections", 1, 4096], ["max_concurrent_bidistream", 1, 1024], ["max_concurrent_unistream", 3, 1024], ["max_idle_timeout", 0, 86400]]) inputs[name] = field(grid, name, `h3_${name}`, binding.http3?.[name] ?? h3Defaults[name], "number", { min, max, required: true });
|
for (const [name, min, max] of [["alt_svc_max_age", 0, 604800], ["max_concurrent_connections", 1, 4096], ["max_concurrent_bidistream", 1, 1024], ["max_concurrent_unistream", 3, 1024], ["max_idle_timeout", 0, 86400], ["keep_alive_interval", 0, 3600]]) inputs[name] = field(grid, name, `h3_${name}`, binding.http3?.[name] ?? h3Defaults[name], "number", { min, max, required: true });
|
||||||
|
const keepAliveMode = field(grid, "keep_alive_mode", "h3_keep_alive_mode", binding.http3?.keep_alive_mode ?? h3Defaults.keep_alive_mode, "select", { values: [["active_requests", "h3KeepAliveActiveRequests"], ["always", "h3KeepAliveAlways"]] });
|
||||||
for (const direction of ["receive", "send"]) {
|
for (const direction of ["receive", "send"]) {
|
||||||
const name = `udp_${direction}_buffer_bytes`;
|
const name = `udp_${direction}_buffer_bytes`;
|
||||||
const mib = (binding.http3?.[name] ?? h3Defaults[name]) / 1048576;
|
const mib = (binding.http3?.[name] ?? h3Defaults[name]) / 1048576;
|
||||||
inputs[name] = field(grid, name, `h3_udp_${direction}_buffer_mib`, mib, "number", { min: 0, max: 16, step: "any", required: true });
|
inputs[name] = field(grid, name, `h3_udp_${direction}_buffer_mib`, mib, "number", { min: 0, max: 16, step: "any", required: true });
|
||||||
}
|
}
|
||||||
box.append(label("p", "h3TuningHelp", "fine"));
|
box.append(label("p", "h3TuningHelp", "fine"));
|
||||||
const sync = (blocked = false) => { for (const input of Object.values(inputs)) input.disabled = blocked; };
|
const sync = (blocked = false) => { for (const input of Object.values(inputs)) input.disabled = blocked; keepAliveMode.disabled = blocked; };
|
||||||
sync(false);
|
sync(false);
|
||||||
const read = () => {
|
const read = () => {
|
||||||
const value = {};
|
const value = { keep_alive_mode: keepAliveMode.value };
|
||||||
for (const [name, input] of Object.entries(inputs)) {
|
for (const [name, input] of Object.entries(inputs)) {
|
||||||
let number = Number(input.value);
|
let number = Number(input.value);
|
||||||
if (!input.value.trim() || !Number.isFinite(number)) throw fieldError(input, t("vhJsonInvalid"));
|
if (!input.value.trim() || !Number.isFinite(number)) throw fieldError(input, t("vhJsonInvalid"));
|
||||||
@@ -111,6 +112,7 @@
|
|||||||
if (!Number.isSafeInteger(number)) throw fieldError(input, t("vhJsonInvalid"));
|
if (!Number.isSafeInteger(number)) throw fieldError(input, t("vhJsonInvalid"));
|
||||||
value[name] = number;
|
value[name] = number;
|
||||||
}
|
}
|
||||||
|
if (value.keep_alive_interval > 0 && value.max_idle_timeout > 0 && value.keep_alive_interval >= value.max_idle_timeout) throw fieldError(inputs.keep_alive_interval, t("h3KeepAliveTooLong"));
|
||||||
return value;
|
return value;
|
||||||
};
|
};
|
||||||
return { read, sync };
|
return { read, sync };
|
||||||
|
|||||||
+20
-2
@@ -294,6 +294,7 @@ pub async fn serve(bound: Bound, router: Router, state: Arc<App>, grace: Duratio
|
|||||||
};
|
};
|
||||||
let router=router.clone();let state=state.clone();let address=bound.address;
|
let router=router.clone();let state=state.clone();let address=bound.address;
|
||||||
let limit=settings.max_concurrent_bidistream as usize;
|
let limit=settings.max_concurrent_bidistream as usize;
|
||||||
|
let idle_close=settings.idle_close_without_requests();
|
||||||
tasks.spawn(async move {
|
tasks.spawn(async move {
|
||||||
let connection=tokio::select! {
|
let connection=tokio::select! {
|
||||||
_=state.shutdown.cancelled()=>return,
|
_=state.shutdown.cancelled()=>return,
|
||||||
@@ -328,7 +329,7 @@ pub async fn serve(bound: Bound, router: Router, state: Arc<App>, grace: Duratio
|
|||||||
state.metrics.http3_active_connections.fetch_add(1,Ordering::Relaxed);
|
state.metrics.http3_active_connections.fetch_add(1,Ordering::Relaxed);
|
||||||
state.metrics.tls_connections.fetch_add(1,Ordering::Relaxed);
|
state.metrics.tls_connections.fetch_add(1,Ordering::Relaxed);
|
||||||
let _lease=Lease {_permit:permit,metrics:state.metrics.clone()};
|
let _lease=Lease {_permit:permit,metrics:state.metrics.clone()};
|
||||||
if let Err(error)=connection_loop(connection,local,router,state.clone(),limit,grace,tls_sni.clone()).await {
|
if let Err(error)=connection_loop(connection,local,router,state.clone(),limit,grace,tls_sni.clone(),idle_close).await {
|
||||||
log_protocol_error(
|
log_protocol_error(
|
||||||
&state, "http3_connection_error", &error, peer, local, 0, None, None, tls_sni,
|
&state, "http3_connection_error", &error, peer, local, 0, None, None, tls_sni,
|
||||||
);
|
);
|
||||||
@@ -353,6 +354,7 @@ async fn connection_loop(
|
|||||||
limit: usize,
|
limit: usize,
|
||||||
grace: Duration,
|
grace: Duration,
|
||||||
tls_sni: Option<String>,
|
tls_sni: Option<String>,
|
||||||
|
idle_close: Option<Duration>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let mut builder = h3::server::builder();
|
let mut builder = h3::server::builder();
|
||||||
builder.max_field_section_size(32 * 1024);
|
builder.max_field_section_size(32 * 1024);
|
||||||
@@ -364,6 +366,10 @@ async fn connection_loop(
|
|||||||
let mut draining = false;
|
let mut draining = false;
|
||||||
let deadline = tokio::time::sleep(Duration::from_secs(86400));
|
let deadline = tokio::time::sleep(Duration::from_secs(86400));
|
||||||
tokio::pin!(deadline);
|
tokio::pin!(deadline);
|
||||||
|
let idle_after = idle_close.unwrap_or(Duration::from_secs(86400));
|
||||||
|
let idle = tokio::time::sleep(idle_after);
|
||||||
|
tokio::pin!(idle);
|
||||||
|
let mut idle_closed = false;
|
||||||
loop {
|
loop {
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
biased;
|
biased;
|
||||||
@@ -372,7 +378,15 @@ async fn connection_loop(
|
|||||||
h3.shutdown(0).await?;
|
h3.shutdown(0).await?;
|
||||||
},
|
},
|
||||||
_=&mut deadline,if draining=>break,
|
_=&mut deadline,if draining=>break,
|
||||||
_=requests.join_next(),if !requests.is_empty()=>{},
|
_=requests.join_next(),if !requests.is_empty()=>{
|
||||||
|
if requests.is_empty() { idle.as_mut().reset(tokio::time::Instant::now()+idle_after); }
|
||||||
|
},
|
||||||
|
_=&mut idle,if idle_close.is_some() && requests.is_empty() && !draining=>{
|
||||||
|
tracing::debug!(peer=%connection.remote_address(), "HTTP/3 connection idle without requests; closing");
|
||||||
|
draining=true;idle_closed=true;
|
||||||
|
deadline.as_mut().reset(tokio::time::Instant::now()+grace.min(Duration::from_secs(1)));
|
||||||
|
h3.shutdown(0).await?;
|
||||||
|
},
|
||||||
next=h3.accept()=>match next {
|
next=h3.accept()=>match next {
|
||||||
Ok(Some(resolver))=>{
|
Ok(Some(resolver))=>{
|
||||||
if requests.len()>=limit {
|
if requests.len()>=limit {
|
||||||
@@ -556,6 +570,10 @@ async fn connection_loop(
|
|||||||
.await;
|
.await;
|
||||||
requests.abort_all();
|
requests.abort_all();
|
||||||
while requests.join_next().await.is_some() {}
|
while requests.join_next().await.is_some() {}
|
||||||
|
if idle_closed {
|
||||||
|
connection.close(0x100u32.into(), b"idle");
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
if draining {
|
if draining {
|
||||||
let _ = tokio::time::timeout(grace, connection.closed()).await;
|
let _ = tokio::time::timeout(grace, connection.closed()).await;
|
||||||
}
|
}
|
||||||
|
|||||||
+33
-1
@@ -1,3 +1,11 @@
|
|||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
|
||||||
|
#[serde(rename_all = "snake_case")]
|
||||||
|
pub enum KeepAliveMode {
|
||||||
|
#[default]
|
||||||
|
ActiveRequests,
|
||||||
|
Always,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
#[serde(default, deny_unknown_fields)]
|
#[serde(default, deny_unknown_fields)]
|
||||||
pub struct Settings {
|
pub struct Settings {
|
||||||
@@ -6,6 +14,8 @@ pub struct Settings {
|
|||||||
pub max_concurrent_bidistream: u32,
|
pub max_concurrent_bidistream: u32,
|
||||||
pub max_concurrent_unistream: u32,
|
pub max_concurrent_unistream: u32,
|
||||||
pub max_idle_timeout: u64,
|
pub max_idle_timeout: u64,
|
||||||
|
pub keep_alive_interval: u64,
|
||||||
|
pub keep_alive_mode: KeepAliveMode,
|
||||||
pub udp_receive_buffer_bytes: u32,
|
pub udp_receive_buffer_bytes: u32,
|
||||||
pub udp_send_buffer_bytes: u32,
|
pub udp_send_buffer_bytes: u32,
|
||||||
}
|
}
|
||||||
@@ -17,6 +27,8 @@ impl Default for Settings {
|
|||||||
max_concurrent_bidistream: 100,
|
max_concurrent_bidistream: 100,
|
||||||
max_concurrent_unistream: 100,
|
max_concurrent_unistream: 100,
|
||||||
max_idle_timeout: 10,
|
max_idle_timeout: 10,
|
||||||
|
keep_alive_interval: 0,
|
||||||
|
keep_alive_mode: KeepAliveMode::ActiveRequests,
|
||||||
udp_receive_buffer_bytes: 4 * 1024 * 1024,
|
udp_receive_buffer_bytes: 4 * 1024 * 1024,
|
||||||
udp_send_buffer_bytes: 4 * 1024 * 1024,
|
udp_send_buffer_bytes: 4 * 1024 * 1024,
|
||||||
}
|
}
|
||||||
@@ -41,6 +53,16 @@ impl Settings {
|
|||||||
self.max_idle_timeout <= 86400,
|
self.max_idle_timeout <= 86400,
|
||||||
"HTTP/3 idle timeout must be 0..86400 seconds"
|
"HTTP/3 idle timeout must be 0..86400 seconds"
|
||||||
);
|
);
|
||||||
|
ensure!(
|
||||||
|
self.keep_alive_interval <= 3600,
|
||||||
|
"HTTP/3 keep-alive interval must be 0..3600 seconds"
|
||||||
|
);
|
||||||
|
ensure!(
|
||||||
|
self.keep_alive_interval == 0
|
||||||
|
|| self.max_idle_timeout == 0
|
||||||
|
|| self.keep_alive_interval < self.max_idle_timeout,
|
||||||
|
"HTTP/3 keep-alive interval must be shorter than the QUIC idle timeout"
|
||||||
|
);
|
||||||
for (name, value) in [
|
for (name, value) in [
|
||||||
("receive", self.udp_receive_buffer_bytes),
|
("receive", self.udp_receive_buffer_bytes),
|
||||||
("send", self.udp_send_buffer_bytes),
|
("send", self.udp_send_buffer_bytes),
|
||||||
@@ -66,7 +88,17 @@ impl Settings {
|
|||||||
.stream_receive_window((256 * 1024u32).into())
|
.stream_receive_window((256 * 1024u32).into())
|
||||||
.receive_window((8 * 1024 * 1024u32).into())
|
.receive_window((8 * 1024 * 1024u32).into())
|
||||||
.send_window(8 * 1024 * 1024)
|
.send_window(8 * 1024 * 1024)
|
||||||
.datagram_receive_buffer_size(None);
|
.datagram_receive_buffer_size(None)
|
||||||
|
.keep_alive_interval(
|
||||||
|
(self.keep_alive_interval > 0)
|
||||||
|
.then(|| Duration::from_secs(self.keep_alive_interval)),
|
||||||
|
);
|
||||||
Ok(transport)
|
Ok(transport)
|
||||||
}
|
}
|
||||||
|
pub fn idle_close_without_requests(&self) -> Option<Duration> {
|
||||||
|
(self.keep_alive_interval > 0
|
||||||
|
&& self.keep_alive_mode == KeepAliveMode::ActiveRequests
|
||||||
|
&& self.max_idle_timeout > 0)
|
||||||
|
.then(|| Duration::from_secs(self.max_idle_timeout))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -22,6 +22,54 @@ mod tests {
|
|||||||
.is_ok());
|
.is_ok());
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
|
fn keep_alive_is_off_by_default_and_validated() {
|
||||||
|
let s = Settings::default();
|
||||||
|
assert_eq!(s.keep_alive_interval, 0);
|
||||||
|
assert_eq!(s.keep_alive_mode, KeepAliveMode::ActiveRequests);
|
||||||
|
assert!(s.idle_close_without_requests().is_none());
|
||||||
|
let on = Settings {
|
||||||
|
max_idle_timeout: 30,
|
||||||
|
keep_alive_interval: 15,
|
||||||
|
..s
|
||||||
|
};
|
||||||
|
assert!(on.transport().is_ok());
|
||||||
|
assert_eq!(
|
||||||
|
on.idle_close_without_requests(),
|
||||||
|
Some(Duration::from_secs(30))
|
||||||
|
);
|
||||||
|
assert!(Settings {
|
||||||
|
keep_alive_mode: KeepAliveMode::Always,
|
||||||
|
..on
|
||||||
|
}
|
||||||
|
.idle_close_without_requests()
|
||||||
|
.is_none());
|
||||||
|
assert!(Settings {
|
||||||
|
max_idle_timeout: 10,
|
||||||
|
keep_alive_interval: 10,
|
||||||
|
..s
|
||||||
|
}
|
||||||
|
.validate()
|
||||||
|
.is_err());
|
||||||
|
let unlimited = Settings {
|
||||||
|
max_idle_timeout: 0,
|
||||||
|
keep_alive_interval: 20,
|
||||||
|
..s
|
||||||
|
};
|
||||||
|
assert!(unlimited.validate().is_ok());
|
||||||
|
assert!(unlimited.idle_close_without_requests().is_none());
|
||||||
|
assert!(Settings {
|
||||||
|
keep_alive_interval: 3601,
|
||||||
|
max_idle_timeout: 0,
|
||||||
|
..s
|
||||||
|
}
|
||||||
|
.validate()
|
||||||
|
.is_err());
|
||||||
|
let json: Settings =
|
||||||
|
serde_json::from_str(r#"{"keep_alive_interval":5,"keep_alive_mode":"always"}"#)
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(json.keep_alive_mode, KeepAliveMode::Always);
|
||||||
|
}
|
||||||
|
#[test]
|
||||||
fn critical_streams_and_resource_limits_are_validated() {
|
fn critical_streams_and_resource_limits_are_validated() {
|
||||||
assert!(Settings {
|
assert!(Settings {
|
||||||
max_concurrent_unistream: 2,
|
max_concurrent_unistream: 2,
|
||||||
|
|||||||
Reference in new issue
Block a user