Fix TypeError when processing a detached watcher#88
Conversation
This patch will fix a race condition where `Coolio_Loop_process_event` attempts to process an event for a watcher that has already been detached. When detach is called (e.g., from another thread or a preceding callback in the same loop cycle), the watcher's loop reference is cleared to nil. If an event for this watcher was already pending in the libev queue, the subsequent processing step causes an TypeError: ``` TypeError: wrong argument type nil (expected Coolio::Loop) ``` The patch will add a check to ensure the watcher is still enabled before accessing the loop data. If the watcher is detached (enabled == 0), the pending event is ignored.
|
@ioquatix Can you look this PR? |
|
Do you think you can add a test? |
I will try to add test. Thanks. |
|
@ioquatix Sorry for late. I added the test for this PR. |
|
Hmm, is the segfault related? |
|
It is difficult to say for sure without seeing the stack trace, but it is highly likely related. Since macOS uses I will look the SEGV later. |
|
When Object X is freed (during finalizer) you cannot usually access other objects it referenced, as they may also be freed at the same time (and before the current object is finalized). Not sure if that applies here, but it's something I've run into in the past. |
|
I have updated the PR to fix the SEGV issue on macOS as well. The crash on macOS was caused by a race condition where |
Fix #87
This patch will fix a race condition where
Coolio_Loop_process_eventattempts to process an event for a watcher that has already been detached.When detach is called (e.g., from another thread or a preceding callback in the same loop cycle), the watcher's loop reference is cleared to nil.
If an event for this watcher was already pending in the libev queue, the subsequent processing step causes an TypeError:
The patch will add a check to ensure the watcher is still enabled before accessing the loop data. If the watcher is detached (enabled == 0), the pending event is ignored.
Types of Changes
Contribution