Skip to content

Commit af8d36e

Browse files
committed
asyncioreactor: make sure task isn't deleted midway
in push function, self._loop.create_task is called and it's return value is ignored. While the tests may pass now, this code is not correct and this example is called out in docs as a source of bugs, as python docs suggests. Ref: https://docs.python.org/3/library/asyncio-task.html#asyncio.create_task
1 parent 1cc6ccc commit af8d36e

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

cassandra/io/asyncioreactor.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,10 @@ def push(self, data):
176176
)
177177
else:
178178
# avoid races/hangs by just scheduling this, not using threadsafe
179-
self._loop.create_task(self._push_msg(chunks))
179+
background_tasks = set()
180+
task = self._loop.create_task(self._push_msg(chunks))
181+
background_tasks.add(task)
182+
task.add_done_callback(background_tasks.discard)
180183

181184
async def _push_msg(self, chunks):
182185
# This lock ensures all chunks of a message are sequential in the Queue

0 commit comments

Comments
 (0)