Commit f95856c
Fix HttpClientResponse body()/end() race (4.x 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 9fe7732 commit f95856c
2 files changed
Lines changed: 135 additions & 38 deletions
File tree
- src
- main/java/io/vertx/core/http/impl
- test/java/io/vertx/core/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 | | |
| |||
51 | 52 | | |
52 | 53 | | |
53 | 54 | | |
54 | | - | |
| 55 | + | |
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
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 | + | |
59 | 92 | | |
60 | 93 | | |
61 | 94 | | |
62 | 95 | | |
63 | 96 | | |
64 | 97 | | |
65 | 98 | | |
| 99 | + | |
66 | 100 | | |
67 | 101 | | |
68 | 102 | | |
| 103 | + | |
69 | 104 | | |
70 | 105 | | |
71 | 106 | | |
| |||
128 | 163 | | |
129 | 164 | | |
130 | 165 | | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
131 | 170 | | |
132 | 171 | | |
133 | 172 | | |
| |||
145 | 184 | | |
146 | 185 | | |
147 | 186 | | |
| 187 | + | |
148 | 188 | | |
149 | | - | |
150 | | - | |
| 189 | + | |
| 190 | + | |
151 | 191 | | |
152 | 192 | | |
153 | 193 | | |
| |||
242 | 282 | | |
243 | 283 | | |
244 | 284 | | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
245 | 289 | | |
246 | | - | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
247 | 300 | | |
248 | 301 | | |
| 302 | + | |
249 | 303 | | |
250 | 304 | | |
251 | 305 | | |
252 | 306 | | |
253 | 307 | | |
254 | 308 | | |
255 | 309 | | |
| 310 | + | |
256 | 311 | | |
257 | | - | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
258 | 316 | | |
259 | 317 | | |
| 318 | + | |
260 | 319 | | |
261 | 320 | | |
| 321 | + | |
262 | 322 | | |
263 | 323 | | |
264 | 324 | | |
| |||
268 | 328 | | |
269 | 329 | | |
270 | 330 | | |
271 | | - | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
272 | 345 | | |
273 | 346 | | |
274 | 347 | | |
275 | | - | |
276 | | - | |
277 | | - | |
| 348 | + | |
| 349 | + | |
278 | 350 | | |
279 | 351 | | |
280 | 352 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
70 | 70 | | |
71 | 71 | | |
72 | 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 | + | |
73 | 104 | | |
74 | 105 | | |
75 | 106 | | |
| |||
3732 | 3763 | | |
3733 | 3764 | | |
3734 | 3765 | | |
3735 | | - | |
| 3766 | + | |
3736 | 3767 | | |
3737 | | - | |
3738 | | - | |
3739 | | - | |
3740 | | - | |
3741 | | - | |
3742 | | - | |
3743 | | - | |
3744 | | - | |
3745 | | - | |
3746 | | - | |
3747 | | - | |
3748 | | - | |
3749 | | - | |
| 3768 | + | |
3750 | 3769 | | |
3751 | 3770 | | |
3752 | 3771 | | |
| |||
3770 | 3789 | | |
3771 | 3790 | | |
3772 | 3791 | | |
3773 | | - | |
3774 | | - | |
3775 | | - | |
3776 | | - | |
3777 | | - | |
3778 | | - | |
3779 | | - | |
3780 | | - | |
3781 | | - | |
3782 | | - | |
3783 | | - | |
3784 | | - | |
3785 | | - | |
| 3792 | + | |
3786 | 3793 | | |
3787 | 3794 | | |
3788 | 3795 | | |
| 3796 | + | |
| 3797 | + | |
3789 | 3798 | | |
3790 | 3799 | | |
3791 | | - | |
3792 | | - | |
| 3800 | + | |
| 3801 | + | |
| 3802 | + | |
| 3803 | + | |
| 3804 | + | |
| 3805 | + | |
| 3806 | + | |
| 3807 | + | |
| 3808 | + | |
| 3809 | + | |
| 3810 | + | |
| 3811 | + | |
| 3812 | + | |
| 3813 | + | |
| 3814 | + | |
| 3815 | + | |
| 3816 | + | |
| 3817 | + | |
3793 | 3818 | | |
3794 | 3819 | | |
3795 | 3820 | | |
| |||
0 commit comments