Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: slow tx task termination #402

Merged
merged 1 commit into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions lib/python/flame/backend/p2p.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,10 @@ def leave(self, channel) -> None:
- for each end id in end ids in the channel, call _cleanup_end(end_id),
which terminates rx task, releases data in _endpoints, _livecheck,
delayed_channel_add and _context_keeper, and calls channel.remove()
Note: channel.remove() terminates tx queue by putting EMPTY_PAYLOAD
in tx queue of the given end

- terminate tx tasks by putting EMPTY_PAYLOAD in tx queue of each task
- terminate broadcast tx task by putting EMPTY_PAYLOAD in tx queue
"""

async def _leave_inner():
Expand Down Expand Up @@ -241,12 +243,9 @@ async def _leave_inner():
# removed this channel from self._channels
await channel.remove(end_id)

# we use EMPTY_PAYLOAD as signal to finish tx tasks
# we use EMPTY_PAYLOAD as signal to finish broadcast tx task
# put EMPTY_PAYLOAD to broadcast queue
await channel._bcast_queue.put(EMPTY_PAYLOAD)
for _, end in channel._ends.items():
# put EMPTY_PAYLOAD to unicast queue for each end
await end.put(EMPTY_PAYLOAD)

await self.await_tx_tasks_done(channel.name())

Expand Down
4 changes: 4 additions & 0 deletions lib/python/flame/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,11 +486,15 @@ async def remove(self, end_id):
return

rxq = self._ends[end_id].get_rxq()
txq = self._ends[end_id].get_txq()
del self._ends[end_id]

# put bogus data to unblock a get() call
await rxq.put(EMPTY_PAYLOAD)

# put bogus data to let tx_task finish
await txq.put(EMPTY_PAYLOAD)

if len(self._ends) == 0:
# clear (or unset) the event
self.await_join_event.clear()
Expand Down