Commit 8d08377
committed
fix(concurrency): Close race windows in cancel and completion paths
Address findings F1-F8 and Review22-F3/F4 from round 3 concurrency review:
- F1: Always route EnvironmentScriptRunner.cancel() through pending-cancel path
- F2+F4: Atomic terminal arbitration - claim pending cancel in _on_process_exit,
move liveness check inside lock in _cancel
- F3: Monotonic merge for duplicate pending cancels (min time_limit, OR failed)
- F5: Snapshot action_status before publishing READY state
- F6: Wrap cancel_info.json write in try/except, fallback to immediate terminate
- F7: Detect self-join in shutdown(), use wait=False if called from worker thread
- F8: Move callback outside lock, wrap in try/except to prevent child discard
- Review22-F3: Snapshot _runner in cancel_action to avoid bare AssertionError
- Review22-F4: Bind _process once in notify/terminate to avoid TOCTOU race
Add test_concurrency_fixes.py with 8 unit tests covering the defensive behaviors.
None of these issues reproduce in openjd-rs due to CancellationToken, tokio async,
and Rust's Result<> error handling model.
Signed-off-by: David Leong <116610336+leongdl@users.noreply.github.com>1 parent a954917 commit 8d08377
5 files changed
Lines changed: 491 additions & 28 deletions
File tree
- src/openjd/sessions
- test/openjd/sessions_v0
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
589 | 589 | | |
590 | 590 | | |
591 | 591 | | |
592 | | - | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
593 | 609 | | |
594 | 610 | | |
595 | 611 | | |
| |||
936 | 952 | | |
937 | 953 | | |
938 | 954 | | |
939 | | - | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
940 | 973 | | |
941 | 974 | | |
942 | 975 | | |
| |||
957 | 990 | | |
958 | 991 | | |
959 | 992 | | |
960 | | - | |
961 | | - | |
962 | | - | |
963 | 993 | | |
964 | 994 | | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
965 | 1005 | | |
966 | 1006 | | |
967 | 1007 | | |
| |||
1015 | 1055 | | |
1016 | 1056 | | |
1017 | 1057 | | |
1018 | | - | |
1019 | | - | |
1020 | | - | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
1021 | 1084 | | |
1022 | 1085 | | |
1023 | 1086 | | |
| |||
1046 | 1109 | | |
1047 | 1110 | | |
1048 | 1111 | | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
1049 | 1119 | | |
1050 | 1120 | | |
1051 | 1121 | | |
| |||
1062 | 1132 | | |
1063 | 1133 | | |
1064 | 1134 | | |
1065 | | - | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
1066 | 1141 | | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
1067 | 1149 | | |
1068 | 1150 | | |
1069 | 1151 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
272 | 272 | | |
273 | 273 | | |
274 | 274 | | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
280 | | - | |
281 | | - | |
282 | | - | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
283 | 285 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
657 | 657 | | |
658 | 658 | | |
659 | 659 | | |
660 | | - | |
661 | | - | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
662 | 670 | | |
663 | | - | |
| 671 | + | |
664 | 672 | | |
665 | 673 | | |
666 | 674 | | |
| |||
2238 | 2246 | | |
2239 | 2247 | | |
2240 | 2248 | | |
| 2249 | + | |
| 2250 | + | |
| 2251 | + | |
| 2252 | + | |
| 2253 | + | |
| 2254 | + | |
| 2255 | + | |
| 2256 | + | |
| 2257 | + | |
| 2258 | + | |
| 2259 | + | |
2241 | 2260 | | |
2242 | 2261 | | |
2243 | 2262 | | |
| |||
2247 | 2266 | | |
2248 | 2267 | | |
2249 | 2268 | | |
2250 | | - | |
2251 | | - | |
2252 | | - | |
2253 | | - | |
| 2269 | + | |
2254 | 2270 | | |
2255 | 2271 | | |
2256 | 2272 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
227 | 227 | | |
228 | 228 | | |
229 | 229 | | |
230 | | - | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
231 | 235 | | |
232 | 236 | | |
233 | 237 | | |
| |||
243 | 247 | | |
244 | 248 | | |
245 | 249 | | |
246 | | - | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
247 | 253 | | |
248 | 254 | | |
249 | 255 | | |
250 | 256 | | |
251 | | - | |
| 257 | + | |
252 | 258 | | |
253 | 259 | | |
254 | | - | |
| 260 | + | |
255 | 261 | | |
256 | 262 | | |
257 | 263 | | |
| |||
0 commit comments