Commit 2561124
Fix estrdup crash by calling sapi.startup() inside spawn_blocking
The crash in CI occurred because estrdup was being called before PHP's
memory allocator was properly initialized on the worker thread. The root
cause was identified through debug logging that showed the crash happened
at the first estrdup call after ThreadScope::new().
The fix adds a sapi.startup() call inside spawn_blocking, after
ThreadScope::new() but before any estrdup calls. This mirrors the main
branch behavior where self.sapi.startup() was called in every handle()
before estrdup operations.
Key changes:
- Added Sapi::startup() method that calls the SAPI module startup function
- Call sapi.startup() inside spawn_blocking to initialize PHP's memory
allocator on the worker thread
- Removed debug logging that was added to diagnose the crash
The SAPI startup (php_module_startup) sets up per-thread state needed
for emalloc/estrdup to work. Without it, ts_resource(0) alone doesn't
fully initialize the memory allocator on ZTS builds.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <[email protected]>1 parent 40761fc commit 2561124
3 files changed
+36
-46
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
341 | 341 | | |
342 | 342 | | |
343 | 343 | | |
344 | | - | |
345 | 344 | | |
346 | | - | |
347 | | - | |
| 345 | + | |
| 346 | + | |
348 | 347 | | |
349 | | - | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
350 | 354 | | |
351 | 355 | | |
352 | 356 | | |
353 | | - | |
354 | 357 | | |
355 | 358 | | |
356 | 359 | | |
357 | 360 | | |
358 | 361 | | |
359 | 362 | | |
360 | | - | |
361 | 363 | | |
362 | | - | |
363 | 364 | | |
364 | | - | |
365 | | - | |
366 | | - | |
367 | | - | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
368 | 368 | | |
369 | | - | |
370 | | - | |
371 | | - | |
372 | 369 | | |
373 | | - | |
374 | | - | |
375 | | - | |
376 | 370 | | |
377 | | - | |
378 | | - | |
379 | | - | |
380 | 371 | | |
381 | | - | |
382 | | - | |
383 | | - | |
384 | 372 | | |
385 | 373 | | |
386 | | - | |
387 | | - | |
388 | | - | |
389 | | - | |
| 374 | + | |
390 | 375 | | |
391 | | - | |
392 | 376 | | |
393 | 377 | | |
394 | 378 | | |
395 | | - | |
396 | | - | |
397 | | - | |
398 | | - | |
399 | | - | |
400 | | - | |
401 | | - | |
402 | | - | |
403 | | - | |
404 | | - | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
405 | 385 | | |
406 | 386 | | |
407 | 387 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
117 | 135 | | |
118 | 136 | | |
119 | 137 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | | - | |
25 | 23 | | |
26 | 24 | | |
27 | 25 | | |
28 | | - | |
29 | 26 | | |
30 | 27 | | |
31 | 28 | | |
32 | 29 | | |
33 | 30 | | |
34 | 31 | | |
35 | | - | |
36 | | - | |
37 | 32 | | |
38 | 33 | | |
39 | 34 | | |
40 | | - | |
41 | 35 | | |
42 | 36 | | |
43 | 37 | | |
| |||
73 | 67 | | |
74 | 68 | | |
75 | 69 | | |
76 | | - | |
77 | 70 | | |
78 | 71 | | |
79 | 72 | | |
| |||
88 | 81 | | |
89 | 82 | | |
90 | 83 | | |
91 | | - | |
92 | 84 | | |
93 | 85 | | |
94 | 86 | | |
| |||
0 commit comments