Repository navigation
Commit 3bb5d7c
committed
[BUG] Publish the operation once, and complete it only at the end
Startup handed the operation out in pieces. The Session route went out
before the callback, and the promise was created after the first event,
so a cancel arriving in between could reach an operation whose callback
was still empty. Whoever noticed that cleanup had started could then
publish the completion, which meant FinishSession could return while the
IO thread was still inside a user handler.
The route is now the last thing stored. Nothing else can bring the IO
thread to this operation: Abort only raises a flag, and the abort queue
is reached through that same route, so by the time the operation is
reachable the callback, the promise and the future all exist. Cleanup is
then the only thing that ever fulfils the promise, at its tail, after the
terminal event and the completion callback have run, and the recheck that
used to fulfil it from the caller is gone.
A promise that exists before the first event would make a handler calling
FinishSession from that event wait on itself, which is what the late
future used to avoid. A thread local scope answers it directly: every
user callback runs inside one, and Finish returns early when the calling
thread is already inside a callback for this operation. It returns before
the finished flag, so a caller outside the callback still gets to wait,
which the flag used to swallow.
Measured with a handler that holds inside the terminal event for 200 ms.
Before, on the runs where the IO thread delivered that event, Finish
returned in 0 ms with the handler still running. After, it waits 400 ms,
the length of the two held events, and the handler is never still running
when it returns: 6 runs of 6.
The case that came out of that probe is on the branch, and its comment
says what it does not prove. Which thread delivers the terminal event is
not something it can choose, and on the caller-thread schedule there is
nothing for Finish to wait for, so reverting this change leaves it green
10 times in 10. The evidence above is the before and after, not that case.
33 tests pass, 3 of 3.
Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>1 parent f930429 commit 3bb5d7c
2 files changed
Lines changed: 128 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
413 | 413 | | |
414 | 414 | | |
415 | 415 | | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
416 | 449 | | |
417 | 450 | | |
418 | 451 | | |
| |||
422 | 455 | | |
423 | 456 | | |
424 | 457 | | |
| 458 | + | |
425 | 459 | | |
426 | 460 | | |
427 | 461 | | |
| |||
514 | 548 | | |
515 | 549 | | |
516 | 550 | | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
517 | 559 | | |
518 | 560 | | |
519 | 561 | | |
| |||
572 | 614 | | |
573 | 615 | | |
574 | 616 | | |
| 617 | + | |
575 | 618 | | |
576 | 619 | | |
577 | 620 | | |
| |||
1472 | 1515 | | |
1473 | 1516 | | |
1474 | 1517 | | |
1475 | | - | |
1476 | | - | |
1477 | | - | |
1478 | | - | |
1479 | | - | |
1480 | | - | |
1481 | | - | |
| 1518 | + | |
1482 | 1519 | | |
1483 | 1520 | | |
1484 | 1521 | | |
1485 | 1522 | | |
1486 | | - | |
1487 | | - | |
1488 | | - | |
1489 | | - | |
1490 | | - | |
1491 | | - | |
1492 | | - | |
1493 | | - | |
1494 | | - | |
| 1523 | + | |
| 1524 | + | |
| 1525 | + | |
| 1526 | + | |
| 1527 | + | |
| 1528 | + | |
| 1529 | + | |
1495 | 1530 | | |
1496 | 1531 | | |
1497 | 1532 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
912 | 912 | | |
913 | 913 | | |
914 | 914 | | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
915 | 992 | | |
916 | 993 | | |
917 | 994 | | |
| |||
0 commit comments