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

connection_init_timeout - "task destroyed but it is pending!" #2460

Open
nrbnlulu opened this issue Jan 16, 2023 · 4 comments
Open

connection_init_timeout - "task destroyed but it is pending!" #2460

nrbnlulu opened this issue Jan 16, 2023 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@nrbnlulu
Copy link
Member

nrbnlulu commented Jan 16, 2023

Describe the Bug

If a gql_transport_ws connection ended before connection_init_timeout asncio will warn:
(if there were no event loops after the task was closed)

Task was destroyed but it is pending!
task: <Task pending name='Task-5' coro=<BaseGraphQLTransportWSHandler.handle_connection_init_timeout() running at /home/nir/Desktop/opensource/forks/strawberry/strawberry/subscriptions/protocols/graphql_transport_ws/handlers.py:75> wait_for=<Future pending cb=[Task.task_wakeup()]>>

Very annoying for tests.
repro:

async def test_connection_init_timeout():
    client = WebsocketCommunicator(
        GraphQLWSConsumer.as_asgi(
            schema=schema,
            # uncomment this and no warning will occure
            # connection_init_wait_timeout=timedelta(seconds=0),
            subscription_protocols=(GRAPHQL_TRANSPORT_WS_PROTOCOL,),
        ),
        "/graphql",
        subprotocols=[
            GRAPHQL_TRANSPORT_WS_PROTOCOL,
        ],
    )
    await asyncio.sleep(0.1)
    # Hope that the connection init timeout expired
    res = await client.connect()
    assert res == (True, GRAPHQL_TRANSPORT_WS_PROTOCOL)

    data = await client.receive_output()
    assert data["type"] == "websocket.close"
    assert data["code"] == 4408

System Information

  • Operating system: ubuntu 22.0.4
  • Strawberry version (if applicable): 0.154.0
  • Python: 3.10

Additional Context

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
@nrbnlulu nrbnlulu added the bug Something isn't working label Jan 16, 2023
@DoctorJohn DoctorJohn self-assigned this Jan 18, 2023
@tsmith023
Copy link
Contributor

@DoctorJohn, I'll have a look at this in the next few days :)

@nrbnlulu
Copy link
Member Author

This might have been resolved by #2600

@tsmith023
Copy link
Contributor

tsmith023 commented Mar 14, 2023

I'm still seeing it in the testing logs:

Task was destroyed but it is pending!
task: <Task pending name='Task-615' coro=<BaseGraphQLTransportWSHandler.handle_connection_init_timeout() running at /home/tommy/Desktop/strawberry/strawberry/subscriptions/protocols/graphql_transport_ws/handlers.py:82> wait_for=<Future pending cb=[Task.task_wakeup()]>>

but it only throws once at the end of the entire suite. I'll dig into it!

@rossmeredith
Copy link

rossmeredith commented Feb 18, 2024

This still seems to be a problem which means websockets can't be tested. This is the simple test I have where I'm encountering this error.

@pytest.mark.asyncio
@pytest.mark.django_db
async def test_subscription():

    from strawberry.channels import GraphQLWSConsumer
    from api.schema import schema

    gql_ws_consumer = GraphQLWSConsumer.as_asgi(
        schema=schema,
        subscription_protocols=(GRAPHQL_TRANSPORT_WS_PROTOCOL,),
    )

    ws_communicator = WebsocketCommunicator(gql_ws_consumer, "/api/graphql")

    connected, subprotocol = await ws_communicator.connect()
    assert connected

Can this have a higher priority please since it's been so long since the last comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants