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

New transport AIOHTTPWebsocketsTransport #478

Merged
merged 64 commits into from
Jul 25, 2024

Conversation

tlowery-scwx
Copy link
Contributor

@tlowery-scwx tlowery-scwx commented May 9, 2024

This represents ongoing work addressing issues #418 and #451, adding AIOHTTP Websockets support with a new AIOHTTPWebsocketsTransport. We already have a working base model, and are working on full parity and test coverage, and wanted to make this work available for review or comment.

This transport allows to run queries including subscriptions on websockets endpoints without using the websockets dependency (only the aiohttp dependency).

Note: a lot of code had to be duplicated from the WebsocketsTransport class. A refactor will be done to reduce the duplicated code in a subsequent PR.

@leszekhanusz
Copy link
Collaborator

Thanks for your PR.
To fix the lint issue, you can use make check (See CONTRIBUTING.md)

@leszekhanusz
Copy link
Collaborator

Hi @tlowery-scwx. Thanks for your work so far.

I took the liberty to take over your branch to try to fix the remaining problems, you can check the commits above.

I had to copy yet again some code from the previous websockets_base.py file (ListenerQueue...) so that it would be possible to run the new transport without needing the websockets dependency. I'll proceed in two steps, first put everything in the aiohttp_websockets.py file and make it work in this PR, then when this PR has been merged, I'll refactor everything to follow DRY in another PR.

The aiohttp_websocket pytest mark has been removed. There was a bit of confusion here, the goal of those pytest marks are there to select tests based on the installed dependencies, so only aiohttp and websockets marks make sense. Something annoying now is that we still need the websockets dependency to test the new transport as we still use websockets for the server part in the tests, so both marks are set for the tests of the new transport. I'll try to implement a new websocket server using the aiohttp dependency so that we could be sure that all tests are passing without the previous websockets dependency.

One of the main problem was that the aiohttp session was not closed properly. For that it is a bit tricky because of still remaining aiohttp issues which should be fixed in aiohttp 4.0 I suppose. Fortunately we are already doing that for our aiohttp transport so I copied the code from there.

During the testing, it appeared that the aiohttp session was still not closed properly for some tests, and it revealed that the problem was already present for the previous websockets transport for some conditions. I fixed that in the PRs #486 and #488, which have been merged in this branch and made the required changes in this branch.

Regarding the edge case with the TransportClosed exception in the _receive method, to fix the code coverage, at first I simply replaced that check with an assertion, as there is not point to have code for which we don't know how to trigger it. I see now that you have made a test which is skipped where you set the transport.websocket to None and discovered other problems here (hanging indefinitely). I'm now thinking reverting that change and reinforcing the _close_coro method so it is more resilient. And instead of checking if self.websocket is None in the _fail method (to see if the transport has already been closed), we can instead check the status of the self._wait_closed event instead. I'll implement that in a following commit. We should also add a configurable timeout for waiting for the close in case of unforeseen problems there.

If you don't mind I'll continue to work on this branch for a few days before asking for your review so please don't add new commits for the time being.

@leszekhanusz leszekhanusz marked this pull request as ready for review July 17, 2024 19:14
@leszekhanusz leszekhanusz changed the title WIP: Aiohttp websockets New transport AIOHTTPWebsocketsTransport Jul 17, 2024
@leszekhanusz
Copy link
Collaborator

@tlowery-scwx It should be ok now. What do you think?

@tlowery-scwx
Copy link
Contributor Author

@leszekhanusz, thank you so much for taking this on, putting so much work into it, and getting it over the finish line! May we have a day to test this transport with our use case and get back to you by EOD tomorrow (USA Pacific time) before you merge and close this out?

@tlowery-scwx
Copy link
Contributor Author

Hi @leszekhanusz -- sorry for taking a bit longer than planned, but we've done quite a bit of testing, and everything looks great from our end. Thank you again for all of your work and help getting this done!

@leszekhanusz leszekhanusz merged commit 00b61d5 into graphql-python:master Jul 25, 2024
13 checks passed
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

Successfully merging this pull request may close these issues.

3 participants