Skip to content

Commit e78ff33

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 e78ff33

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

cassandra/io/asyncioreactor.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,13 @@ def push(self, data):
175175
loop=self._loop
176176
)
177177
else:
178+
background_tasks = set()
179+
178180
# avoid races/hangs by just scheduling this, not using threadsafe
179-
self._loop.create_task(self._push_msg(chunks))
181+
task = self._loop.create_task(self._push_msg(chunks))
182+
183+
background_tasks.add(task)
184+
task.add_done_callback(background_tasks.discard)
180185

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

0 commit comments

Comments
 (0)