Skip to content

Commit 58392db

Browse files
Add logging: trace blocking_operation through execute/exception/cancel paths
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent b1d4ed9 commit 58392db

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

ext/io/event/worker_pool.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include <string.h>
1616

1717
enum {
18-
DEBUG = 1,
18+
DEBUG = 0,
1919
};
2020

2121
static VALUE IO_Event_WorkerPool;
@@ -146,9 +146,11 @@ static void worker_unblock_func(void *_worker) {
146146
pthread_mutex_unlock(&pool->mutex);
147147

148148
// If there's a currently executing blocking operation, cancel it
149-
// if (worker->current_blocking_operation) {
150-
// rb_fiber_scheduler_blocking_operation_cancel(worker->current_blocking_operation);
151-
// }
149+
if (worker->current_blocking_operation) {
150+
fprintf(stderr, "[worker_pool] unblock: cancelling blocking_operation=%p\n",
151+
(void*)worker->current_blocking_operation);
152+
rb_fiber_scheduler_blocking_operation_cancel(worker->current_blocking_operation);
153+
}
152154
}
153155

154156
// Function to wait for work and execute it without GVL.
@@ -177,6 +179,8 @@ static void *worker_wait_and_execute(void *_worker) {
177179

178180
// Execute work WITHOUT GVL (this is the whole point!)
179181
if (work) {
182+
fprintf(stderr, "[worker_pool] execute: blocking_operation=%p\n",
183+
(void*)work->blocking_operation);
180184
worker->current_blocking_operation = work->blocking_operation;
181185
rb_fiber_scheduler_blocking_operation_execute(work->blocking_operation);
182186
worker->current_blocking_operation = NULL;
@@ -376,6 +380,11 @@ static VALUE worker_pool_call(VALUE self, VALUE _blocking_operation) {
376380
if (DEBUG) fprintf(stderr, "<- worker_pool_call:work completed=%d, state=%d\n", work.completed, state);
377381

378382
if (state) {
383+
// Exception path: cleanup in rb_fiber_scheduler_blocking_operation_wait is
384+
// bypassed (operation->state becomes a dangling pointer to our caller's stack).
385+
// Log the blocking_operation so we can correlate with any later cancel calls.
386+
fprintf(stderr, "[worker_pool] exception path: blocking_operation=%p state_tag=%d\n",
387+
(void*)blocking_operation, state);
379388
rb_jump_tag(state);
380389
} else {
381390
return Qtrue;

0 commit comments

Comments
 (0)