Skip to content

Commit bd491ca

Browse files
Qardclaude
andcommitted
Add debug logging to diagnose CI crash location
Adding eprintln statements to track: - Thread ID for ThreadScope new/drop - Each step in spawn_blocking closure - Each estrdup call This will help identify exactly where the crash occurs in CI. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent def1902 commit bd491ca

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/embed.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ impl Drop for BlockingTaskHandle {
4141
if let Some(handle) = guard.take() {
4242
// Use block_on to wait for the task to complete
4343
// This ensures ThreadScope::drop() runs and PHP TLS is cleaned up
44-
let _ = crate::sapi::fallback_handle().block_on(async move {
45-
let _ = handle.await;
46-
});
44+
let _ = crate::sapi::fallback_handle().block_on(handle);
4745
}
4846
}
4947
}
@@ -343,31 +341,43 @@ impl Handler for Embed {
343341

344342
// Spawn blocking PHP execution - ALL PHP operations happen here
345343
let blocking_handle = tokio::task::spawn_blocking(move || {
344+
eprintln!("[DEBUG] spawn_blocking: starting");
346345
// Keep sapi alive for the duration of this task
347346
let _sapi = _sapi;
347+
eprintln!("[DEBUG] spawn_blocking: creating ThreadScope");
348348
let _thread_scope = ThreadScope::new();
349+
eprintln!("[DEBUG] spawn_blocking: ThreadScope created");
349350

350351
// Setup RequestContext (always streaming from SAPI perspective)
351352
// RequestContext::new() will extract the request body's read stream and add it as RequestStream extension
353+
eprintln!("[DEBUG] spawn_blocking: creating RequestContext");
352354
let ctx = RequestContext::new(
353355
request,
354356
docroot.clone(),
355357
response_writer.clone(),
356358
headers_sent_tx,
357359
);
360+
eprintln!("[DEBUG] spawn_blocking: setting RequestContext::current");
358361
RequestContext::set_current(Box::new(ctx));
362+
eprintln!("[DEBUG] spawn_blocking: RequestContext set");
359363

360364
// All estrdup calls MUST happen here, inside spawn_blocking, after ThreadScope::new()
361365
// has initialized PHP's memory manager for this thread.
362366
// These will be freed by efree in sapi_module_deactivate during request shutdown.
367+
eprintln!("[DEBUG] spawn_blocking: calling estrdup for request_uri_str");
363368
let request_uri_c = estrdup(request_uri_str.as_str());
369+
eprintln!("[DEBUG] spawn_blocking: calling estrdup for path_translated");
364370
let path_translated = estrdup(translated_path_str.as_str());
371+
eprintln!("[DEBUG] spawn_blocking: calling estrdup for request_method");
365372
let request_method = estrdup(method_str.as_str());
373+
eprintln!("[DEBUG] spawn_blocking: calling estrdup for query_string");
366374
let query_string = estrdup(query_str.as_str());
375+
eprintln!("[DEBUG] spawn_blocking: calling estrdup for content_type");
367376
let content_type = content_type_str
368377
.as_ref()
369378
.map(|s| estrdup(s.as_str()))
370379
.unwrap_or(std::ptr::null_mut());
380+
eprintln!("[DEBUG] spawn_blocking: estrdup calls complete");
371381

372382
// Prepare argv pointers
373383
let argc = args.len() as i32;

src/scopes.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,24 @@ pub(crate) struct ThreadScope();
2020

2121
impl ThreadScope {
2222
pub fn new() -> Self {
23+
let thread_id = std::thread::current().id();
24+
eprintln!("[DEBUG] ThreadScope::new() on thread {:?} - calling ext_php_rs_sapi_per_thread_init", thread_id);
2325
unsafe {
2426
ext_php_rs_sapi_per_thread_init();
2527
}
28+
eprintln!("[DEBUG] ThreadScope::new() on thread {:?} - ext_php_rs_sapi_per_thread_init complete", thread_id);
2629
Self()
2730
}
2831
}
2932

3033
impl Drop for ThreadScope {
3134
fn drop(&mut self) {
35+
let thread_id = std::thread::current().id();
36+
eprintln!("[DEBUG] ThreadScope::drop() on thread {:?} - calling ext_php_rs_sapi_per_thread_shutdown", thread_id);
3237
unsafe {
3338
ext_php_rs_sapi_per_thread_shutdown();
3439
}
40+
eprintln!("[DEBUG] ThreadScope::drop() on thread {:?} - ext_php_rs_sapi_per_thread_shutdown complete", thread_id);
3541
}
3642
}
3743

0 commit comments

Comments
 (0)