Repository navigation
Commit b073ecd
committed
xds: avoid IllegalStateException on sendMessage/halfClose after internal cancellation
When RawMessageClientInterceptor or ExternalProcessorClientInterceptor
encounters an internal error (such as an IOException while reading the
request InputStream in sendMessage) and cancels the underlying call, the
application is not synchronously aware that the call was cancelled.
Callers such as ClientCalls.blockingUnaryCall immediately invoke
halfClose() after sendMessage(), which previously delegated to the
already-cancelled downstream call and threw
IllegalStateException("call was cancelled"), masking the underlying
CANCELLED status and cause.
Fix this by tracking internal cancellation (`aborted`) separately from
explicit application-initiated cancellation (`cancelCalled`):
1. RawMessageClientInterceptor (PartialForwardingClientCall):
- Move `sendSerializedMessage` into `PartialForwardingClientCall` so
`sendMessage`, `halfClose`, and `cancel` share per-call state.
- Set `aborted = true` when `sendSerializedMessage` catches an
`IOException` or `RuntimeException` and cancels `rawCall`, making
subsequent `sendMessage()` and `halfClose()` calls no-ops (matching
`ClientCallImpl.sendMessageInternal` when it cancels the underlying
stream internally).
- Set `cancelCalled = true` (and `aborted = false`) in `cancel()` and
delegate `rawCall.sendMessage(null)` before stream serialization
when `cancelCalled` is true, ensuring `sendMessage()` and
`halfClose()` after explicit application cancellation still throw
`IllegalStateException("call was cancelled")`.
2. ExternalProcessorClientInterceptor (DataPlaneClientCall):
- Set `aborted = true` in `cancelDownstream()` when triggered
internally (`!cancelCalled.get()`), turning subsequent
`sendMessage()`, `halfClose()`, and `proceedWithHalfClose()` calls
into no-ops.
- Set `cancelCalled = true` (and `aborted = false`) in `cancel()` and
check `!cancelCalled.get()` in `sendMessage()` and `halfClose()` so
explicit application cancellation enforces `IllegalStateException`
even when requests or half-close would otherwise be buffered or
sent to the ext_proc sidecar without synchronously reaching
`delayedCall`.
TAG=agy
CONV=56c87717-243d-4f12-af9e-c532e509892a1 parent 15d64a4 commit b073ecd
4 files changed
Lines changed: 202 additions & 24 deletions
File tree
- xds/src
- main/java/io/grpc/xds
- test/java/io/grpc/xds
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
366 | 367 | | |
367 | 368 | | |
368 | 369 | | |
| 370 | + | |
| 371 | + | |
369 | 372 | | |
370 | 373 | | |
371 | 374 | | |
| |||
994 | 997 | | |
995 | 998 | | |
996 | 999 | | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
997 | 1004 | | |
998 | 1005 | | |
999 | 1006 | | |
| |||
1080 | 1087 | | |
1081 | 1088 | | |
1082 | 1089 | | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
1083 | 1093 | | |
1084 | 1094 | | |
1085 | 1095 | | |
| |||
1090 | 1100 | | |
1091 | 1101 | | |
1092 | 1102 | | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
1093 | 1107 | | |
1094 | 1108 | | |
1095 | 1109 | | |
| |||
1159 | 1173 | | |
1160 | 1174 | | |
1161 | 1175 | | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
1162 | 1179 | | |
1163 | 1180 | | |
1164 | 1181 | | |
1165 | 1182 | | |
1166 | 1183 | | |
| 1184 | + | |
| 1185 | + | |
1167 | 1186 | | |
1168 | 1187 | | |
1169 | 1188 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1283 | 1283 | | |
1284 | 1284 | | |
1285 | 1285 | | |
1286 | | - | |
1287 | | - | |
1288 | | - | |
1289 | | - | |
1290 | | - | |
1291 | | - | |
1292 | | - | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
1293 | 1305 | | |
1294 | | - | |
1295 | | - | |
| 1306 | + | |
1296 | 1307 | | |
1297 | | - | |
1298 | | - | |
1299 | | - | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
1300 | 1315 | | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
1301 | 1323 | | |
1302 | | - | |
1303 | | - | |
1304 | | - | |
1305 | | - | |
1306 | | - | |
1307 | | - | |
| 1324 | + | |
1308 | 1325 | | |
1309 | | - | |
1310 | | - | |
1311 | | - | |
1312 | | - | |
1313 | | - | |
1314 | | - | |
1315 | 1326 | | |
1316 | 1327 | | |
1317 | 1328 | | |
| |||
1320 | 1331 | | |
1321 | 1332 | | |
1322 | 1333 | | |
| 1334 | + | |
| 1335 | + | |
1323 | 1336 | | |
1324 | 1337 | | |
1325 | 1338 | | |
1326 | 1339 | | |
1327 | 1340 | | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
1328 | 1344 | | |
1329 | 1345 | | |
1330 | 1346 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
11423 | 11424 | | |
11424 | 11425 | | |
11425 | 11426 | | |
| 11427 | + | |
| 11428 | + | |
| 11429 | + | |
| 11430 | + | |
| 11431 | + | |
| 11432 | + | |
| 11433 | + | |
| 11434 | + | |
| 11435 | + | |
| 11436 | + | |
| 11437 | + | |
| 11438 | + | |
| 11439 | + | |
| 11440 | + | |
| 11441 | + | |
| 11442 | + | |
| 11443 | + | |
| 11444 | + | |
| 11445 | + | |
| 11446 | + | |
| 11447 | + | |
| 11448 | + | |
| 11449 | + | |
| 11450 | + | |
| 11451 | + | |
| 11452 | + | |
| 11453 | + | |
| 11454 | + | |
| 11455 | + | |
| 11456 | + | |
| 11457 | + | |
| 11458 | + | |
| 11459 | + | |
| 11460 | + | |
| 11461 | + | |
| 11462 | + | |
| 11463 | + | |
| 11464 | + | |
| 11465 | + | |
| 11466 | + | |
| 11467 | + | |
| 11468 | + | |
| 11469 | + | |
| 11470 | + | |
| 11471 | + | |
| 11472 | + | |
| 11473 | + | |
| 11474 | + | |
| 11475 | + | |
| 11476 | + | |
| 11477 | + | |
| 11478 | + | |
| 11479 | + | |
| 11480 | + | |
| 11481 | + | |
| 11482 | + | |
| 11483 | + | |
| 11484 | + | |
| 11485 | + | |
| 11486 | + | |
| 11487 | + | |
| 11488 | + | |
| 11489 | + | |
| 11490 | + | |
| 11491 | + | |
| 11492 | + | |
| 11493 | + | |
| 11494 | + | |
| 11495 | + | |
| 11496 | + | |
| 11497 | + | |
| 11498 | + | |
| 11499 | + | |
| 11500 | + | |
| 11501 | + | |
| 11502 | + | |
| 11503 | + | |
| 11504 | + | |
| 11505 | + | |
| 11506 | + | |
| 11507 | + | |
| 11508 | + | |
| 11509 | + | |
| 11510 | + | |
| 11511 | + | |
| 11512 | + | |
| 11513 | + | |
| 11514 | + | |
| 11515 | + | |
| 11516 | + | |
| 11517 | + | |
| 11518 | + | |
| 11519 | + | |
| 11520 | + | |
| 11521 | + | |
| 11522 | + | |
| 11523 | + | |
| 11524 | + | |
| 11525 | + | |
| 11526 | + | |
| 11527 | + | |
| 11528 | + | |
| 11529 | + | |
| 11530 | + | |
| 11531 | + | |
| 11532 | + | |
| 11533 | + | |
| 11534 | + | |
11426 | 11535 | | |
11427 | 11536 | | |
11428 | 11537 | | |
| |||
12136 | 12245 | | |
12137 | 12246 | | |
12138 | 12247 | | |
| 12248 | + | |
| 12249 | + | |
| 12250 | + | |
| 12251 | + | |
| 12252 | + | |
12139 | 12253 | | |
12140 | 12254 | | |
12141 | 12255 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
75 | 76 | | |
76 | 77 | | |
77 | 78 | | |
| 79 | + | |
78 | 80 | | |
79 | 81 | | |
80 | 82 | | |
| |||
3227 | 3229 | | |
3228 | 3230 | | |
3229 | 3231 | | |
| 3232 | + | |
| 3233 | + | |
| 3234 | + | |
| 3235 | + | |
3230 | 3236 | | |
3231 | 3237 | | |
3232 | 3238 | | |
| |||
3235 | 3241 | | |
3236 | 3242 | | |
3237 | 3243 | | |
| 3244 | + | |
| 3245 | + | |
| 3246 | + | |
| 3247 | + | |
| 3248 | + | |
| 3249 | + | |
| 3250 | + | |
| 3251 | + | |
| 3252 | + | |
| 3253 | + | |
| 3254 | + | |
| 3255 | + | |
| 3256 | + | |
| 3257 | + | |
| 3258 | + | |
| 3259 | + | |
| 3260 | + | |
| 3261 | + | |
| 3262 | + | |
| 3263 | + | |
| 3264 | + | |
| 3265 | + | |
| 3266 | + | |
3238 | 3267 | | |
3239 | 3268 | | |
3240 | 3269 | | |
| |||
0 commit comments