Commit 6d525c4
Motivation:
This issue was found while working on `GrpcServicesPreprocessor`
refactoring.
Currently, there is a bug where exceptions/response failures in
`Preprocessor` do not complete `ctx.whenInitialized`.
e.g.
```
WebClient.of((delegate, ctx, req) -> {
// ctx.whenInitialized will not be completed
throw new RuntimeException("error");
}).get("/");
```
While normally this may not be an issue, gRPC relies on completion of
this future to signal errors:
ref:
https://github.com/line/armeria/blob/1a31f3e8c9aba91fb663bfe5c4fc3eaa87c9d13f/grpc/src/main/java/com/linecorp/armeria/internal/client/grpc/ArmeriaClientCall.java#L180
I propose two modifications to resolve this issue:
- When a Preprocessor throws an exception from the `PreClient#execute`
calling thread, it should complete the ctx
```
WebClient.of((delegate, ctx, req) -> {
throw new RuntimeException("error");
}).get("/");
```
- When `ctx.cancel` is called (even before `ctx.init`) is called, it
should complete the ctx
```
WebClient.of((delegate, ctx, req) -> {
ctx.cancel(e);
return HttpResponse.of(400);
}).get("/");
```
Modifications:
- Introduced an `initialized` flag to guard against concurrent
initialization attempts
- `finishInitialization` is also modified to guard against concurrent
calls
- A new `initAndFail` method is introduced which acquires an event loop,
initializes the cancellation scheduler, and completes the ctx
- `ctx.cancel` will trigger `initAndFail` if the ctx is not initialized
yet
- If `PreClient#execute` throws an exception, `initAndFail` is called
- For derived contexts, if an endpoint does not exist, it means
`ClientUtil#initContextAnd*` needs to be called. Hence, initialization
is set only if an endpoint exists.
- `responseCancellationScheduler.finishNow` is called in
`DefaultClientRequestContext#failEarly` to record `cancellationCause`
consistently.
- `XdsPreprocessor` and `RouterFilter` now calls `ctx.cancel` if a
request is short-circuited before `ctx.init` is called.
Result:
- Requests failed at the `XdsPreprocessor`-level are propagated to the
user correctly when using gRPC.
<!--
Visit this URL to learn more about how to write a pull request
description:
https://armeria.dev/community/developer-guide#how-to-write-pull-request-description
-->
---------
Co-authored-by: Ikhun Um <ikhun.um@linecorp.com>
1 parent 36f4e38 commit 6d525c4
18 files changed
Lines changed: 397 additions & 36 deletions
File tree
- core/src
- main/java/com/linecorp/armeria
- client
- retry
- common
- internal
- client
- common
- test/java/com/linecorp/armeria/client
- grpc/src
- main/java/com/linecorp/armeria/internal/client/grpc
- test/java/com/linecorp/armeria/client/grpc
- it/xds-client/src/test/java/com/linecorp/armeria/xds/it
- thrift/thrift0.13/src/main/java/com/linecorp/armeria/internal/client/thrift
- xds/src/main/java/com/linecorp/armeria/xds/client/endpoint
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
129 | | - | |
| 129 | + | |
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
| |||
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
325 | 325 | | |
326 | 326 | | |
327 | 327 | | |
328 | | - | |
| 328 | + | |
329 | 329 | | |
330 | 330 | | |
331 | 331 | | |
| 332 | + | |
332 | 333 | | |
333 | 334 | | |
334 | 335 | | |
335 | 336 | | |
| 337 | + | |
336 | 338 | | |
337 | 339 | | |
338 | 340 | | |
| |||
Lines changed: 1 addition & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
30 | 29 | | |
31 | 30 | | |
32 | 31 | | |
| |||
184 | 183 | | |
185 | 184 | | |
186 | 185 | | |
187 | | - | |
188 | | - | |
189 | | - | |
| 186 | + | |
190 | 187 | | |
191 | 188 | | |
192 | 189 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| 74 | + | |
74 | 75 | | |
75 | 76 | | |
Lines changed: 12 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
68 | 80 | | |
69 | 81 | | |
70 | 82 | | |
| |||
Lines changed: 12 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
169 | 169 | | |
170 | 170 | | |
171 | 171 | | |
172 | | - | |
173 | | - | |
174 | | - | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
175 | 175 | | |
176 | 176 | | |
177 | 177 | | |
178 | 178 | | |
| 179 | + | |
179 | 180 | | |
180 | | - | |
| 181 | + | |
181 | 182 | | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
182 | 186 | | |
183 | | - | |
| 187 | + | |
184 | 188 | | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
185 | 192 | | |
186 | 193 | | |
187 | 194 | | |
| |||
Lines changed: 62 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| |||
116 | 117 | | |
117 | 118 | | |
118 | 119 | | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
119 | 124 | | |
120 | 125 | | |
121 | 126 | | |
| |||
134 | 139 | | |
135 | 140 | | |
136 | 141 | | |
137 | | - | |
| 142 | + | |
| 143 | + | |
138 | 144 | | |
139 | 145 | | |
140 | 146 | | |
| |||
358 | 364 | | |
359 | 365 | | |
360 | 366 | | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
361 | 370 | | |
362 | | - | |
363 | | - | |
364 | 371 | | |
365 | 372 | | |
366 | 373 | | |
| |||
383 | 390 | | |
384 | 391 | | |
385 | 392 | | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
386 | 416 | | |
387 | 417 | | |
388 | 418 | | |
| |||
395 | 425 | | |
396 | 426 | | |
397 | 427 | | |
| 428 | + | |
398 | 429 | | |
399 | 430 | | |
400 | 431 | | |
| |||
404 | 435 | | |
405 | 436 | | |
406 | 437 | | |
| 438 | + | |
407 | 439 | | |
408 | 440 | | |
409 | 441 | | |
| |||
412 | 444 | | |
413 | 445 | | |
414 | 446 | | |
| 447 | + | |
415 | 448 | | |
416 | 449 | | |
417 | 450 | | |
| |||
462 | 495 | | |
463 | 496 | | |
464 | 497 | | |
465 | | - | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
466 | 501 | | |
467 | 502 | | |
468 | 503 | | |
469 | 504 | | |
470 | 505 | | |
471 | | - | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
472 | 509 | | |
473 | 510 | | |
474 | 511 | | |
| |||
484 | 521 | | |
485 | 522 | | |
486 | 523 | | |
487 | | - | |
488 | 524 | | |
489 | 525 | | |
490 | 526 | | |
| |||
540 | 576 | | |
541 | 577 | | |
542 | 578 | | |
| 579 | + | |
543 | 580 | | |
544 | 581 | | |
545 | 582 | | |
| |||
616 | 653 | | |
617 | 654 | | |
618 | 655 | | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
619 | 659 | | |
620 | 660 | | |
621 | 661 | | |
622 | 662 | | |
623 | | - | |
624 | 663 | | |
625 | 664 | | |
626 | 665 | | |
| 666 | + | |
627 | 667 | | |
628 | 668 | | |
629 | | - | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
630 | 673 | | |
631 | 674 | | |
632 | 675 | | |
| |||
683 | 726 | | |
684 | 727 | | |
685 | 728 | | |
686 | | - | |
| 729 | + | |
687 | 730 | | |
688 | 731 | | |
689 | 732 | | |
| |||
789 | 832 | | |
790 | 833 | | |
791 | 834 | | |
792 | | - | |
| 835 | + | |
793 | 836 | | |
794 | 837 | | |
795 | | - | |
796 | 838 | | |
797 | 839 | | |
798 | 840 | | |
| |||
820 | 862 | | |
821 | 863 | | |
822 | 864 | | |
823 | | - | |
| 865 | + | |
824 | 866 | | |
825 | 867 | | |
826 | 868 | | |
| |||
1035 | 1077 | | |
1036 | 1078 | | |
1037 | 1079 | | |
1038 | | - | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
1039 | 1088 | | |
1040 | 1089 | | |
1041 | 1090 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
| 82 | + | |
83 | 83 | | |
84 | 84 | | |
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
| 136 | + | |
| 137 | + | |
136 | 138 | | |
137 | 139 | | |
138 | 140 | | |
| |||
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
273 | 273 | | |
274 | 274 | | |
275 | 275 | | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
276 | 281 | | |
277 | 282 | | |
278 | 283 | | |
| |||
0 commit comments