Commit 4336ca6
committed
Unify HTTP/1 and HTTP/2 pool, fix 1xx handling
The previous pool design split HTTP/1 and HTTP/2 into separate modules
and probed ALPN in the caller process. That caller opened the socket,
then tried to hand it off to a worker via `controlling_process/2` — which
fails with `:not_owner` when called from anywhere except the current
socket owner. The "fix" in HTTP1.Worker.init/1 (calling
`controlling_process(conn, self())` from the worker) could never have
worked at runtime; the HTTP/2 path had the same latent bug.
Replaced the HTTP1/HTTP1.Worker/HTTP2 modules with a unified design:
* Hex.HTTP.Pool.Host (one GenServer per {scheme, host, port}) owns a
pool of Conn processes. On start it spawns two probe Conns; when the
first reports its protocol it scales up to 8 for :http1 or stays at
2 for :http2. Dispatches by least in-flight to the Conn with free
capacity; queues waiters otherwise.
* Hex.HTTP.Pool.Conn (one GenServer per Mint connection) connects
inside its own process, so the socket is owned from birth — no
controlling_process handoff ever needed. Reports negotiated protocol
and per-conn capacity (1 for HTTP/1, server's max_concurrent_streams
for HTTP/2) back to its host. Requests arrive as casts carrying the
caller's `from`; Conn replies directly to the caller and casts back
:req_done so the host decrements in-flight. Handles GOAWAY by
draining in-flight then reconnecting with exponential backoff.
* Hex.HTTP.Pool now just wires up the Registry + DynamicSupervisor and
routes requests to the Host for a given {scheme, host, port}. No
more probe phase, no ETS cache, no initial_conn plumbing.
Also fixes 1xx informational response handling in the vendored Mint
HTTP/1 module, which previously emitted `:done` and popped the request
after a 100 Continue / 103 Early Hints etc., causing the real final
response to arrive with no active request and the connection to close.
Upstream fix submitted as elixir-mint/mint#479; the vendored copy marks
the change with `# HEX PATCH` comments for easy re-application after
re-vendoring.
Conn.process_response resets accumulated headers/data on each new
`:status` so informational headers (e.g. 103 Early Hints `link:`) don't
bleed into the final response. Added bypass-backed regression tests for
100 Continue round-trip, 100 Continue with early error response, and
103 Early Hints with headers. test/mix/tasks/hex.registry_test.exs now
uses `Hex.HTTP.config/0` instead of the raw httpc-defaulting config.1 parent 54c57b3 commit 4336ca6
9 files changed
Lines changed: 508 additions & 828 deletions
File tree
- lib/hex
- http
- pool
- http1
- mint
- test
- hex
- mix/tasks
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
12 | 10 | | |
13 | 11 | | |
14 | 12 | | |
15 | | - | |
16 | | - | |
| 13 | + | |
17 | 14 | | |
18 | 15 | | |
19 | 16 | | |
20 | | - | |
21 | 17 | | |
22 | 18 | | |
23 | 19 | | |
24 | 20 | | |
25 | 21 | | |
26 | 22 | | |
27 | 23 | | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | 24 | | |
36 | 25 | | |
37 | 26 | | |
| |||
54 | 43 | | |
55 | 44 | | |
56 | 45 | | |
| 46 | + | |
57 | 47 | | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | 48 | | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | 49 | | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | 50 | | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
| 51 | + | |
| 52 | + | |
148 | 53 | | |
149 | 54 | | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
159 | 59 | | |
160 | 60 | | |
161 | 61 | | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
171 | 65 | | |
172 | 66 | | |
173 | | - | |
174 | | - | |
| 67 | + | |
| 68 | + | |
175 | 69 | | |
176 | 70 | | |
177 | 71 | | |
| |||
183 | 77 | | |
184 | 78 | | |
185 | 79 | | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
192 | 83 | | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
199 | 87 | | |
200 | | - | |
201 | | - | |
202 | 88 | | |
203 | 89 | | |
204 | 90 | | |
| |||
225 | 111 | | |
226 | 112 | | |
227 | 113 | | |
228 | | - | |
229 | | - | |
230 | 114 | | |
0 commit comments