crossbario / crossbario/autobahn-python

Cancellation of the handlers set to the "ready" event of an asyncio component are not properly handled

Open
#1,123 15 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs-investigation wamp
Dominant language
Python
Stars
2.5k
Forks
768
PR merge metrics
No merged PRs in 30d

Description

After cancelling the handlers associated with the "ready" event a _GatheringFuture exception holding the CancelledError is raised but never retrieved.

@comp.on_ready
async def go(*args, **kwargs):
    while True:
        await asyncio.sleep(1)

run(comp)

gives, after the user initiated a shutdown:

2019-02-22T16:54:47 connecting once using transport type "websocket" over endpoint "tcp"
2019-02-22T16:54:50 Shutting down due to SIGINT
2019-02-22T16:54:50 _GatheringFuture exception was never retrieved
future: <_GatheringFuture finished exception=CancelledError()>
concurrent.futures._base.CancelledError

Just await the handlers solves the issue:

# in autobahn.util.ObservableMixin.fire
for handler in self._listener
    future = txaio.as_future(
    
    def consume_result(fut):
        return fut.result()
    
    future.add_callbacks(consume_result)
    res.append(future)

Related to #1000

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in autobahn.util.ObservableMixin.fire and reproduce the reported asyncio component shutdown with the ready-handler example. Trace how cancelled handlers and the _GatheringFuture are handled during SIGINT shutdown. Done means cancellation no longer leaves an un-retrieved exception while the handlers still shut down correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.