Skip to content

Commit

Permalink
Fix segfault in TimerHandle.when() after cleared
Browse files Browse the repository at this point in the history
Fixes #469
Closes #475

Co-authored-by: Fantix King <fantix.king@gmail.com>
  • Loading branch information
jensbjorgensen and fantix committed Jul 16, 2022
1 parent fcbf422 commit c39afff
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -34,3 +34,4 @@ uvloop/loop.*.pyd
/.eggs
/.venv*
/wheelhouse
/uvloop-dev
8 changes: 8 additions & 0 deletions tests/test_base.py
Expand Up @@ -860,6 +860,14 @@ def test_loop_call_later_handle_when(self):
self.assertAlmostEqual(handle.when(), loop_t + delay, places=2)
handle.cancel()
self.assertTrue(handle.cancelled())
self.assertAlmostEqual(handle.when(), loop_t + delay, places=2)

def test_loop_call_later_handle_when_after_fired(self):
fut = self.loop.create_future()
handle = self.loop.call_later(0.05, fut.set_result, None)
when = handle.when()
self.loop.run_until_complete(fut)
self.assertEqual(handle.when(), when)


class TestBaseAIO(_TestBase, AIOTestCase):
Expand Down
1 change: 1 addition & 0 deletions uvloop/cbhandles.pxd
Expand Up @@ -32,6 +32,7 @@ cdef class TimerHandle:
object context
tuple _debug_info
object __weakref__
object _when

cdef _run(self)
cdef _cancel(self)
Expand Down
3 changes: 2 additions & 1 deletion uvloop/cbhandles.pyx
Expand Up @@ -193,6 +193,7 @@ cdef class TimerHandle:
loop, <method_t>self._run, self, delay)

self.timer.start()
self._when = self.timer.get_when() * 1e-3

# Only add to loop._timers when `self.timer` is successfully created
loop._timers.add(self)
Expand Down Expand Up @@ -309,7 +310,7 @@ cdef class TimerHandle:
self._cancel()

def when(self):
return self.timer.get_when() * 1e-3
return self._when


cdef format_callback_name(func):
Expand Down

0 comments on commit c39afff

Please sign in to comment.