Skip to content

Re-using client after schema fetching failed #296

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

Closed
joricht opened this issue Feb 18, 2022 · 2 comments · Fixed by #297
Closed

Re-using client after schema fetching failed #296

joricht opened this issue Feb 18, 2022 · 2 comments · Fixed by #297
Labels
type: bug An issue or pull request relating to a bug

Comments

@joricht
Copy link
Contributor

joricht commented Feb 18, 2022

Describe the bug
The Client has the option to fetch the GraphQL schem from the transport. This is done when the session is initialized and the program enters the context manager, i.e. when doing the following:

client = Client(transport=AIOHTTPTransport(url), fetch_schema_from_transport=True)
with client as session:
    # do something with the session

However, it can happen that fetching the schema fails. This throws an exception but since the context manager was not completely entered yet, the transport is not closed as it would be when leaving the context manager. When trying to open a new session, this fails with an TransportAlreadyConnected Error.

This only happens when re-using the client object, e.g.,

client = Client(transport=AIOHTTPTransport(url), fetch_schema_from_transport=True)

with client as session:
    # session is not established because the server is not available

...

with client as session:
    # session can now be established

Maybe this is not intended? Should we always create a new client object after an error?

I think this can be easily fixed by catching the error in the __aenter__ method and close the transport. I will add a PR.

To Reproduce
Steps to reproduce the behavior:

  1. Open a client session to a server that is not yet available
  2. Wait until the server is available
  3. Try again to open a client session to the server

Expected behavior
The following should be possible without errors:

client = Client(transport=AIOHTTPTransport(url), fetch_schema_from_transport=True)

try:
    with client as session:
        # session is not established because the server is not available
except Exception:
    pass

sleep(30)

with client as session:
    # session can now be established

System info (please complete the following information):

  • OS: Linux
  • Python version: 3.10
  • gql version: 3.0.0rc0
  • graphql-core version: 3.1.7
@joricht
Copy link
Contributor Author

joricht commented Feb 18, 2022

Added PR #297.

@leszekhanusz leszekhanusz added the type: bug An issue or pull request relating to a bug label Feb 18, 2022
@leszekhanusz
Copy link
Collaborator

Indeed, you are right. See my comments on the PR.

@leszekhanusz leszekhanusz linked a pull request Feb 18, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug An issue or pull request relating to a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants