Skip to content

Commit cf05762

Browse files
committed
Fix cancellation of pending tasks
Formerly, all uncancelled tasks have been treated as if they are done. This resulted in exceptions when trying to fetch the result (or exception) from the task for logging purposes. Now, all tasks are cancelled if they are not already cancelled or not done. WIP: Needs test
1 parent 0d2600d commit cf05762

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Diff for: saltyrtc/server/protocol.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,11 @@ def _cancel_coroutine_or_task(self, coroutine_or_task, mark_as_done=False):
602602
else:
603603
if mark_as_done:
604604
coroutine_or_task.add_done_callback(self.task_done)
605-
if not coroutine_or_task.cancelled():
605+
# Note: We need to check for .cancelled first since a task is also marked
606+
# .done when it is cancelled.
607+
if coroutine_or_task.cancelled():
608+
self.log.debug('Already cancelled task {}', coroutine_or_task)
609+
elif coroutine_or_task.done():
606610
exc = coroutine_or_task.exception()
607611
if exc is not None:
608612
message = 'Ignoring exception of queued task {}: {}'

0 commit comments

Comments
 (0)