-
Notifications
You must be signed in to change notification settings - Fork 40
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
sse-starlette 1.6.1 appears to leak asyncio.Lock across instantiations #59
Comments
Hi @rra, thanks for reporting. However, I cannot reproduce the error. I know that the original PR did not have appropriate tests, but I think I have fixed this before merging. You can check the GH actions where the tests are passing. Running |
I unfortunately don't know how to minimize a test case for you, but here are my GitHub Actions failures: https://github.com/lsst-sqre/jupyterlab-controller/actions/runs/5017943281/jobs/8996712105 The first test that consumes progress events passes, and then the subsequent ones all seem to fail with this error. The only thing I changed to make the error disappear again was to downgrade sse-starlette to 1.6.0. The use of sse-starlette seems to be fairly simple and straightforward; I don't think I'm doing anything weird. The async iterator is here: and the handler is here: The actual translation into a |
I had the same error and it is easy to fix: Reset @pytest.fixture
def reset_appstatus_event():
# avoid: RuntimeError: <asyncio.locks.Event object at 0x1046a0a30 [unset]> is bound to a different event loop
AppStatus.should_exit_event = None |
|
This is strange. Re-init of reset_appstatus_event at the beginning of every did the trick for me. In any case, the issue is purely test related. In any real world app there should be no re-use of event-loop with partially initialised eventsource. However, I am not sure how I can help. I experienced exactly the same issue after merging 57, but for me the fixture resolved the problem. |
For the record, the approach that I went with was to add: AppStatus.should_exit_event = None to the shutdown event handler for my FastAPI webapp. I realize that it's probably a test-specific problem and I could have used a test fixture instead, but this felt a bit cleaner, since when the FastAPI app is shutting down I'd like to discard all state, since it won't be used again until it's reinitialized. (This may not work for other people if their application is juggling multiple FastAPI apps that may be using sse-starlette.) Thanks for the help! |
Thanks for the feedback @rra ! Glad you could solve your problem. |
Don't love that there's this workaround but for reference, this is the fixture that we ended up using to address the same issue @pytest.fixture
def reset_sse_starlette_appstatus_event():
"""
Fixture that resets the appstatus event in the sse_starlette app.
Should be used on any test that uses sse_starlette to stream events.
"""
# See https://github.com/sysid/sse-starlette/issues/59
from sse_starlette.sse import AppStatus
AppStatus.should_exit_event = None |
Thanks for sharing @msukmanowsky . |
The issue is still present on sse-starlette 2.0.0, but the workaround works. |
For the record: @sysid Would you be open to include a small section in the project's readme to guide users in the right direction if they run into this problem while building their tests? |
See sysid#59 for context.
I proposed a small PR to include guidance on this in the Readme: |
With sse-starlette 1.6.1, I'm getting new test failures that all look like this:
I think this may be related to #57. It looks like the
should_exit_event
may not be properly cleared between tests, which causes it to fail because each test uses a separate event loop.Reverting to sse-starlette to 1.6.0 makes this problem go away again.
The text was updated successfully, but these errors were encountered: