Repository navigation
Commit 505dd80
authored
* fix: probe kernel readiness without racing ipykernel initialization (ROADMAP.md #82)
start_session waited for readiness with a single kernel_info_request on the
control channel, sent the instant kernel.json appeared. ipykernel registers
the control dispatcher (kernelbase.py:551) before it assigns _control_lock
(:559), so a probe landing in that window raises TraitError kernel-side and
is dropped — and the one request we sent was then never answered, burning the
whole remaining budget (the 59.5s CI hang).
Readiness now rides the shell channel, whose handler is registered only after
_control_lock is assigned, so a shell reply proves initialization finished.
No execution can be in flight during a start, so the shell channel's
busy-serialization caveat does not apply there.
The probe loop the two helpers duplicated is extracted into
_kernel_info_reply(kc, channel, timeout); _kernel_alive stays the control
wrapper and _kernel_idle becomes _kernel_answers_shell. _kernel_dead,
is_session_running, session_status's liveness check and exec_code's silence
probe still use control: they must answer for a busy kernel, which only
control does.
Adds a stand-in kernel that answers kernel_info on shell only and leaves
control bound but unserviced, which fails in 30s against the old control
probe and passes in ~1s against the new one, plus a real-kernel guard that
fires a control probe the instant kernel.json appears.
* test: deliver the intruder's control probe in the init-race guard
stop_channels() closes the client socket with linger=0, which discards
anything ZMQ has not yet handed over — and right after send() on loopback the
connect handshake is usually still in flight. Measured against a bound ROUTER
with the test's exact code shape: the probe arrived 2/20 times, so
test_start_session_survives_control_probe_during_init was mostly firing
nothing. Holding the socket open until the start finishes takes it to 20/20.
Also from review:
- the intruder now retries instead of giving up when it reads a half-written
connection file, catches only the (OSError, ValueError) _client documents
rather than everything, drops the exists()/stat() TOCTOU, and asserts it
actually finished;
- start_session's comment names the ipykernel version and line numbers the
shell-channel ordering was verified against, since pyproject sets no
ipykernel ceiling;
- the stand-in's cleanup comment gives the real reason conftest's reaper never
sees it (argv is `python -c`, not ipykernel_launcher);
- test_start_session_kernel_never_ready_stops_kernel's docstring names
_kernel_answers_shell, the helper start_session now probes with.
1 parent dc50953 commit 505dd80
2 files changed
Lines changed: 195 additions & 43 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
75 | | - | |
| 74 | + | |
| 75 | + | |
76 | 76 | | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
81 | 80 | | |
82 | 81 | | |
83 | | - | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
84 | 88 | | |
85 | 89 | | |
86 | 90 | | |
| |||
89 | 93 | | |
90 | 94 | | |
91 | 95 | | |
92 | | - | |
| 96 | + | |
93 | 97 | | |
94 | 98 | | |
95 | 99 | | |
96 | 100 | | |
97 | 101 | | |
98 | 102 | | |
99 | | - | |
100 | | - | |
| 103 | + | |
| 104 | + | |
101 | 105 | | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
106 | 110 | | |
107 | | - | |
108 | | - | |
109 | | - | |
| 111 | + | |
110 | 112 | | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
122 | 127 | | |
123 | 128 | | |
124 | 129 | | |
| |||
242 | 247 | | |
243 | 248 | | |
244 | 249 | | |
245 | | - | |
| 250 | + | |
246 | 251 | | |
247 | 252 | | |
248 | 253 | | |
| |||
286 | 291 | | |
287 | 292 | | |
288 | 293 | | |
289 | | - | |
290 | | - | |
| 294 | + | |
| 295 | + | |
291 | 296 | | |
292 | 297 | | |
293 | 298 | | |
| |||
315 | 320 | | |
316 | 321 | | |
317 | 322 | | |
318 | | - | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
319 | 338 | | |
320 | 339 | | |
321 | | - | |
| 340 | + | |
322 | 341 | | |
323 | 342 | | |
324 | 343 | | |
| |||
447 | 466 | | |
448 | 467 | | |
449 | 468 | | |
450 | | - | |
| 469 | + | |
451 | 470 | | |
452 | 471 | | |
453 | 472 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
234 | 235 | | |
235 | 236 | | |
236 | 237 | | |
237 | | - | |
238 | | - | |
239 | | - | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
240 | 241 | | |
241 | 242 | | |
242 | 243 | | |
| |||
265 | 266 | | |
266 | 267 | | |
267 | 268 | | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
268 | 401 | | |
269 | 402 | | |
270 | 403 | | |
| |||
1043 | 1176 | | |
1044 | 1177 | | |
1045 | 1178 | | |
1046 | | - | |
| 1179 | + | |
1047 | 1180 | | |
1048 | | - | |
1049 | | - | |
| 1181 | + | |
| 1182 | + | |
1050 | 1183 | | |
1051 | 1184 | | |
1052 | 1185 | | |
| |||
1075 | 1208 | | |
1076 | 1209 | | |
1077 | 1210 | | |
1078 | | - | |
1079 | | - | |
| 1211 | + | |
| 1212 | + | |
1080 | 1213 | | |
1081 | 1214 | | |
1082 | 1215 | | |
| |||
1091 | 1224 | | |
1092 | 1225 | | |
1093 | 1226 | | |
1094 | | - | |
| 1227 | + | |
1095 | 1228 | | |
1096 | 1229 | | |
1097 | 1230 | | |
| |||
0 commit comments