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

RuntimeError: cannot reuse already awaited coroutine #108

Closed
kinow opened this issue Jan 20, 2020 · 7 comments
Closed

RuntimeError: cannot reuse already awaited coroutine #108

kinow opened this issue Jan 20, 2020 · 7 comments

Comments

@kinow
Copy link
Member

kinow commented Jan 20, 2020

Describe the bug

From: #107 (comment)

The following error happens in runtime:

od IOLoop._discard_future_result of <tornado.platform.asyncio.AsyncIOMainLoop object at 0x7fb41c96e7b8>>, <Task finished coro=<TornadoSubscriptionServer.handle() done, defined at /home/kinow/Development/python/workspace/cylc-uiserver/cylc/uiserver/websockets/tornado.py:79> exception=RuntimeError('cannot reuse already awaited coroutine')>)
Traceback (most recent call last):
  File "/home/kinow/Development/python/workspace/cylc-uiserver/venv/lib/python3.7/site-packages/tornado/ioloop.py", line 743, in _run_callback
    ret = callback()
  File "/home/kinow/Development/python/workspace/cylc-uiserver/venv/lib/python3.7/site-packages/tornado/ioloop.py", line 767, in _discard_future_result
    future.result()
RuntimeError: cannot reuse already awaited coroutine

Release version(s) and/or repository branch(es) affected?

master

Steps to reproduce the bug

Run some workflows for a while, and switch views in the UI. Eventually this errors pops in the console output.

Expected behavior

No errors.

Screenshots

Additional context

@dwsutherland commented:

Might be if the async gen is not being exited correctly, I think it might need the yield within a try: & await/other within a finally: .. doesn’t need to be addressed here.

Pull requests welcome!
This is an Open Source project - please consider contributing a bug fix
yourself (please read CONTRIBUTING.md before starting any work though).

@kinow kinow added the bug Something isn't working label Jan 20, 2020
@kinow kinow added this to the 0.2 milestone Jan 20, 2020
@kinow
Copy link
Member Author

kinow commented Mar 5, 2020

This looks like an normal error that happens when the coroutine that is created by the WebSocket handler

def open(self, *args, **kwargs):
IOLoop.current().spawn_callback(self.subscription_server.handle, self,
self.context)

To quickly reproduce it, just start up the whole Cylc system, then go to the UI, wait for it to load. Now fire a few refreshes (e.g. CTRL + SHIFT + R on Firefox Linux a couple times). The callback will be created, then discarded, and another one will be created, and eventually be used.

Looks like when the callback is added, but discarded, it is awaited twice. My guess is that the first time is the legit call, which is interrupted. Then the second is the normal Tornado code that tries to prevent exceptions not being logged.

image

(this error is logged on that except Exception line that prints "Exception in callback ...")

@kinow
Copy link
Member Author

kinow commented Mar 5, 2020

There are errors that may happen when using WebSockets and can be ignored (e.g. tornadoweb/tornado#2763 (comment)). I guess this error is in the same category. Couldn't find anything we could do to prevent it from being logged without adding a except RuntimeError that looks quite dangerous I guess.

@oliver-sanders
Copy link
Member

Oh dear, this one keeps getting bumped, has anyone managed to reproduce this recently?

@kinow
Copy link
Member Author

kinow commented Aug 31, 2021

Oh dear, this one keeps getting bumped, has anyone managed to reproduce this recently?

I haven't seen this one in a long time. @dwsutherland have you seen this bug?

@oliver-sanders if @dwsutherland confirms he hasn't seen it, tomorrow I will try to reproduce as per issue description above (refreshing the UI), and if I don't see, we can close as cannot reproduce. It might have been fixed by some of the many changes since it was reported 🤷‍♂️

@kinow
Copy link
Member Author

kinow commented Aug 31, 2021

@dwsutherland confirmed in Element he hasn't seen it.

no I haven't, but I'd suggest getting the current batch of fixes in so we can rule them out
maybe reproduce by hitting mutations really fast?

Let's keep it open just until the release. Then we can try firing a few mutations in parallel (craft a command line call and xargs or parallel it?), and refreshing the UI a few times too. If no one is able to reproduce it, then we close it instead of bumping it to the next milestone. WDYT?

@kinow
Copy link
Member Author

kinow commented Sep 1, 2021

I tried to reproduce another issue, and then decided to try this one too. Just for the record, no success in reproducing it after ~5 minutes trying. Switched views (click on the workflow in GScan, then on another one, which stops/starts subscriptions), paused/played. Triggered some tasks. The error never happened 👍

@oliver-sanders
Copy link
Member

I've not seen this for a while either.

The event loop may have changed somewhat since we moved to JupyterServer, tentatively closing now unless we hear of any other reports.

@oliver-sanders oliver-sanders removed this from the cylc-uiserver 0.6.0 milestone Nov 9, 2021
@oliver-sanders oliver-sanders removed the bug Something isn't working label Nov 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants