|
15 | 15 | #include <string.h> |
16 | 16 |
|
17 | 17 | enum { |
18 | | - DEBUG = 1, |
| 18 | + DEBUG = 0, |
19 | 19 | }; |
20 | 20 |
|
21 | 21 | static VALUE IO_Event_WorkerPool; |
@@ -146,9 +146,11 @@ static void worker_unblock_func(void *_worker) { |
146 | 146 | pthread_mutex_unlock(&pool->mutex); |
147 | 147 |
|
148 | 148 | // 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 | + } |
152 | 154 | } |
153 | 155 |
|
154 | 156 | // Function to wait for work and execute it without GVL. |
@@ -177,6 +179,8 @@ static void *worker_wait_and_execute(void *_worker) { |
177 | 179 |
|
178 | 180 | // Execute work WITHOUT GVL (this is the whole point!) |
179 | 181 | if (work) { |
| 182 | + fprintf(stderr, "[worker_pool] execute: blocking_operation=%p\n", |
| 183 | + (void*)work->blocking_operation); |
180 | 184 | worker->current_blocking_operation = work->blocking_operation; |
181 | 185 | rb_fiber_scheduler_blocking_operation_execute(work->blocking_operation); |
182 | 186 | worker->current_blocking_operation = NULL; |
@@ -376,6 +380,11 @@ static VALUE worker_pool_call(VALUE self, VALUE _blocking_operation) { |
376 | 380 | if (DEBUG) fprintf(stderr, "<- worker_pool_call:work completed=%d, state=%d\n", work.completed, state); |
377 | 381 |
|
378 | 382 | 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); |
379 | 388 | rb_jump_tag(state); |
380 | 389 | } else { |
381 | 390 | return Qtrue; |
|
0 commit comments