Commit fb2c8da
committed
[EventLoop] Fix timers when using libevent-based loop.
Since a closure cannot destroy itself from inside its body, to prevent
PHP from raising the fatal error "Cannot destroy active lambda function"
when cancelling a periodic timer from inside its callback we previously
tried to postpone the call to event_free() on the affected libevent
timer resource at a later stage by queueing up timer resources to be
freed. This approach was quite awkward and eventually lead to complex
code, difficult to test and with other unexpected side effects such as
memory leaks in a couple of corner cases.
This new fix greatly reduces code complexity and makes it possible to
free up timer resources immediatly when cancelling a timer: we simply
keep a reference of our internal timer callback from inside itself so
that its refcount is still > 1 when calling event_free(), effectively
preventing PHP's garbage collector to kick in when the closure is
still active.1 parent ce06750 commit fb2c8da
File tree
2 files changed
+3
-16
lines changed- src/React/EventLoop
- tests/React/Tests/EventLoop/Timer
2 files changed
+3
-16
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | 13 | | |
15 | 14 | | |
16 | 15 | | |
| |||
21 | 20 | | |
22 | 21 | | |
23 | 22 | | |
24 | | - | |
25 | | - | |
26 | 23 | | |
27 | 24 | | |
28 | 25 | | |
| |||
171 | 168 | | |
172 | 169 | | |
173 | 170 | | |
174 | | - | |
175 | | - | |
176 | 171 | | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | 172 | | |
| 173 | + | |
182 | 174 | | |
183 | 175 | | |
184 | 176 | | |
185 | | - | |
| 177 | + | |
186 | 178 | | |
187 | 179 | | |
188 | 180 | | |
| |||
216 | 208 | | |
217 | 209 | | |
218 | 210 | | |
219 | | - | |
| 211 | + | |
220 | 212 | | |
221 | 213 | | |
222 | 214 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | 17 | | |
0 commit comments