Skip to content

Extensions execution context can easily overlap between parallel executions. #3571

Open

Description

Describe the Bug

RN extensions can be singleton instances meaning that the execution context can change during
lifepsan hook execution (if you have parallel operaitons running) :

async def test_execution_context_distinct_on_parallel_execution():

    class EnsureDistinctExtension(SchemaExtension):
        def __init__(self) -> None:
            ...
        async def on_operation(self) -> AsyncIterator[None]:
            query = self.execution_context.query
            yield
            assert self.execution_context.query == query

    @strawberry.type
    class Query:
        @strawberry.field
        async def foo(self) -> str:
            await asyncio.sleep(0.01)
            return "pong"

        @strawberry.field
        async def bar(self) -> str:
            await asyncio.sleep(0.02)
            return "pong"

    schema = strawberry.Schema(query=Query, extensions=[EnsureDistinctExtension()])
    query_foo = "query foo { foo }"
    query_bar = "query bar { bar }"
    for _ in range(10):
        results = await asyncio.gather(*[schema.execute(query_foo), schema.execute(query_bar)])

    for res in results:
        assert not res.errors

I want to remove the execution_context from the extension instance and provide it as an argument to each hook
what do you guys think?
original discussion on discord

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions