-
Notifications
You must be signed in to change notification settings - Fork 184
Race condition when connecting with the same websockets transport twice at the same time #105
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
Comments
Hi, Could you please post your code ? The parts where the transports, clients and session are created. Regarding your EDIT2, the So you actually need to use You can get a session from the client by running async with client as session:
# session is available here
That's the spirit except that no Threads are created. The create_task will add the task to the event loop and this task will be run as soon as possible by the event loop. the await will block the coroutine there until the task finishes. EDIT: |
Thanks for your answer @leszekhanusz , I succeeded in making it working, below the before/after cases: Old way with the issue
New way that works
Conclusion/DifferencesThe only difference is that I "factorize" the definition of the At first looking it seems the code should behave the same: Does it seems right to you now? Another quick question, I would like to force the auto-reconnect if the connection closes or something wrong happens. Do I have to deal with it manually with another I see you specified a If you already have an example about the reconnection with the GQL client, it would be really appreciated! Thank you, EDIT: I close the issue since it's solved. If you have any advice about reconnection, I'm still interested to know more about it :) |
You figured it out. The problem was that you used But because of a race condition in the websockets transport it tried to connect twice at the same time... This is a small bug with the transport. Regarding the retries, I use the backoff module which allows to add a decorator to an async function. This will ensure that if a problem happens, it will retry but with a delay which is getting longer for each retry. I plan to add documentation about this: Something like this: @backoff.on_exception(backoff.expo,
Exception,
max_value=60)
async def main():
# your connection here EDIT: |
Indeed having a retry example in the documentation will help 👍 I'm trying to set up it right now, I already did that in Javascript to enable auto-reconnect and it was not that trivial 😄 With the Python library and according to
(In Javascript with my Apollo client I just had to manage the websocket "subclient" to reconnect without dealing with re-subscribing to all subscriptions. I guess the library was dealing with it automatically) But since with Python the multiple Am I right? Thank you again (and sorry for mixing both questions) |
Fixed in version v3.0.0a1 |
Hi @leszekhanusz ,
First of all, thanks again for implementing the subscription part, that's great!
I still get some issues to set up multiple subscriptions and I'm not sure how to solve this. Consider taking your example: https://github.com/graphql-python/gql/blame/master/README.md#L318-L342
Can you confirm me that about subscriptions the
asyncio.create_task(...)
will immediately run the function in another thread, and that all theawait taskX
is to remain the program blocking until each task finishes?On my side even with your example I get this random error (it's not immediate, sometimes after 1 second, sometimes 10...):
The message is pretty explicit but I don't understand how to bypass this 😢
If you have any idea 👍
Thank you,
EDIT: that's weird because sometimes without modifying the code, the process can run more than 5 minutes without having this error...
EDIT2: Note that sometimes I also get this error about the
subscribe(...)
methodEDIT3: If I use a different way of doing async (with the same library)
it works without any error. That's really strange...
The text was updated successfully, but these errors were encountered: