Commit 82b01d9
Fix HttpClientResponse body()/end() race (5.0 backport)
This change fixes the race in `HttpClientResponseImpl` described in #6038: `handleTrailers()`/`handleException()` can run before `body()`/`end()` creates the promise. If that happens, the completion signal is dropped and the future can hang. This is observed from the call site as a HTTP request timeout.
This fix is only applied to `HttpClientResponseImpl`:
- keep ended/failure state on `HttpClientResponseImpl`
- in `body()`/`end()`, create the `HttpEventHandler` promise while holding `synchronized(conn)`
- after unlock, replay completion/failure via `handleEnd()`/`handleException()` when needed
Although `HttpEventHandler` looks very similar (like it _could_ be affected by the same/similar race condition), it is not affected. I intentionally did not change `HttpEventHandler`, because it is also used in server request processing. The only case when server request processing could be affected
, is when `body()` is called from a _different_ thread while `end()` is being processed - that is very unlikely (feels like a misuse).
Also added two new tests to `Http1xTest` that reliably fail without the change to `HttpClientResponseImpl` and reliably pass with that change. The added regression tests are `testResponseBodyAfterResponseEnd` and `testResponseEndAfterResponseEnd`.
Fixes #60381 parent 89878bd commit 82b01d9
2 files changed
Lines changed: 134 additions & 37 deletions
File tree
- vertx-core/src
- main/java/io/vertx/core/http/impl
- test/java/io/vertx/tests/http
Lines changed: 81 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
48 | | - | |
| 49 | + | |
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
52 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 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 | + | |
53 | 86 | | |
54 | 87 | | |
55 | 88 | | |
56 | 89 | | |
57 | 90 | | |
58 | 91 | | |
59 | 92 | | |
| 93 | + | |
60 | 94 | | |
61 | 95 | | |
62 | 96 | | |
| 97 | + | |
63 | 98 | | |
64 | 99 | | |
65 | 100 | | |
| |||
122 | 157 | | |
123 | 158 | | |
124 | 159 | | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
125 | 164 | | |
126 | 165 | | |
127 | 166 | | |
| |||
139 | 178 | | |
140 | 179 | | |
141 | 180 | | |
| 181 | + | |
142 | 182 | | |
143 | | - | |
144 | | - | |
| 183 | + | |
| 184 | + | |
145 | 185 | | |
146 | 186 | | |
147 | 187 | | |
| |||
236 | 276 | | |
237 | 277 | | |
238 | 278 | | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
239 | 283 | | |
240 | | - | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
241 | 294 | | |
242 | 295 | | |
| 296 | + | |
243 | 297 | | |
244 | 298 | | |
245 | 299 | | |
246 | 300 | | |
247 | 301 | | |
248 | 302 | | |
249 | 303 | | |
| 304 | + | |
250 | 305 | | |
251 | | - | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
252 | 310 | | |
253 | 311 | | |
| 312 | + | |
254 | 313 | | |
255 | 314 | | |
| 315 | + | |
256 | 316 | | |
257 | 317 | | |
258 | 318 | | |
| |||
262 | 322 | | |
263 | 323 | | |
264 | 324 | | |
265 | | - | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
266 | 339 | | |
267 | 340 | | |
268 | 341 | | |
269 | | - | |
270 | | - | |
271 | | - | |
| 342 | + | |
| 343 | + | |
272 | 344 | | |
273 | 345 | | |
274 | 346 | | |
| |||
Lines changed: 53 additions & 28 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
50 | 49 | | |
51 | 50 | | |
52 | 51 | | |
| |||
72 | 71 | | |
73 | 72 | | |
74 | 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 | + | |
75 | 105 | | |
76 | 106 | | |
77 | 107 | | |
| |||
3609 | 3639 | | |
3610 | 3640 | | |
3611 | 3641 | | |
| 3642 | + | |
3612 | 3643 | | |
3613 | 3644 | | |
3614 | | - | |
3615 | | - | |
3616 | | - | |
3617 | | - | |
3618 | | - | |
3619 | | - | |
3620 | | - | |
3621 | | - | |
3622 | | - | |
3623 | | - | |
3624 | | - | |
3625 | | - | |
3626 | | - | |
| 3645 | + | |
3627 | 3646 | | |
3628 | 3647 | | |
3629 | 3648 | | |
| |||
3647 | 3666 | | |
3648 | 3667 | | |
3649 | 3668 | | |
3650 | | - | |
3651 | | - | |
3652 | | - | |
3653 | | - | |
3654 | | - | |
3655 | | - | |
3656 | | - | |
3657 | | - | |
3658 | | - | |
3659 | | - | |
3660 | | - | |
3661 | | - | |
3662 | | - | |
| 3669 | + | |
3663 | 3670 | | |
3664 | 3671 | | |
3665 | 3672 | | |
| 3673 | + | |
| 3674 | + | |
3666 | 3675 | | |
3667 | 3676 | | |
3668 | 3677 | | |
3669 | | - | |
| 3678 | + | |
| 3679 | + | |
| 3680 | + | |
| 3681 | + | |
| 3682 | + | |
| 3683 | + | |
| 3684 | + | |
| 3685 | + | |
| 3686 | + | |
| 3687 | + | |
| 3688 | + | |
| 3689 | + | |
| 3690 | + | |
| 3691 | + | |
| 3692 | + | |
| 3693 | + | |
| 3694 | + | |
3670 | 3695 | | |
3671 | 3696 | | |
3672 | 3697 | | |
| |||
0 commit comments