Commit c5ce895
net.http: fix TLS server read/handshake timeouts and idle-shutdown fd race (vlang#27434)
* net.http: bound the TLS server handshake timeout for infinite accept_timeout
The TLS server handshake runs on the accept thread, and its timeout was
derived directly from `accept_timeout` (`handshake_timeout := accept_timeout`).
With `accept_timeout <= 0` (block indefinitely waiting to accept), the handshake
timeout therefore became infinite too, so a client that completes the TCP
connect and then stalls mid-TLS-handshake wedged the accept loop forever: no new
connections were accepted, and `stop()` was never observed. That is the hang
class vlang#27429 set out to remove, still reachable for the `accept_timeout <= 0`
configuration.
Fall back to a finite `tls_handshake_timeout` when `accept_timeout <= 0`.
Note: this reverses the deliberate behavior added in "preserve zero TLS handshake
timeout"; the corresponding test is updated. Flagging for @medvednikov per the
discussion on vlang#27433.
(Item #2 from vlang#27433 — read_timeout ignored on HTTPS — was fixed independently on
master by "fix master ci failures", so it is not included here. The close_idle
fd-reuse race, item #4, is left for a separate change now that master added an
out-of-lock net.close on Windows.)
Refs vlang#27433.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* net.http: make TLS handshake fallback timeout configurable per Server
`tls_handshake_timeout` was a module-level constant with no Server-field
override, inconsistent with `read_timeout`, `write_timeout`, and
`accept_timeout` which are all `pub mut` fields. Add
`Server.tls_handshake_timeout` (default 30 s) and thread it through
`tls_accept_timeouts` as a parameter so users who need a tighter budget
(hardened public-facing server) or a looser one (embedded devices with
slow crypto hardware) can set it directly.
Also fix the misleading doc comment: the fallback fires only when
`accept_timeout` is explicitly zero or `net.infinite_timeout`, not
whenever the user "did not set a finite accept_timeout" (the default is
already finite at 30 s).
Co-Authored-By: WOZCODE <contact@withwoz.com>
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: WOZCODE <contact@withwoz.com>1 parent 4a6645f commit c5ce895
3 files changed
Lines changed: 45 additions & 9 deletions
File tree
- vlib/net/http
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | | - | |
15 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
16 | 30 | | |
17 | 31 | | |
18 | 32 | | |
| |||
80 | 94 | | |
81 | 95 | | |
82 | 96 | | |
83 | | - | |
| 97 | + | |
| 98 | + | |
84 | 99 | | |
85 | 100 | | |
86 | 101 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | | - | |
6 | | - | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
7 | 13 | | |
8 | | - | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
9 | 19 | | |
10 | 20 | | |
11 | 21 | | |
12 | | - | |
| 22 | + | |
| 23 | + | |
13 | 24 | | |
14 | 25 | | |
15 | 26 | | |
16 | 27 | | |
17 | 28 | | |
18 | | - | |
| 29 | + | |
| 30 | + | |
19 | 31 | | |
20 | 32 | | |
21 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
0 commit comments