Skip to content

Make loading somehow context/request aware #121

@werjo-gridfuse

Description

@werjo-gridfuse

Hello,

There is a significant issue when using DataLoaders in scenarios with multiple concurrent HTTP requests.

Currently, the DataLoader batches requests purely based on a predefined time window. This can cause multiple HTTP requests—potentially with different bearer access tokens and contexts—to be grouped into the same batch. The batch is then executed using the context of the first request in the batch.

Issues

  1. Incorrect results for request-specific data
    If the DataLoader relies on request-specific data (e.g. access tokens, user identity, permissions), the results will be incorrect for all other requests in the batch.

  2. Cancellation leakage between requests
    If one request (or its context) is cancelled, it can negatively affect other unrelated requests that were batched together.

Expected behavior

I initially assumed that DataLoaders were scoped per request/context, but this does not appear to be the case.

Proposed solution

It would be very helpful to have an option to scope DataLoader batching based on the request context. For example, introducing a new option such as:

WithContextScopeHandler(...)

This handler could inspect the current context and decide when a new batch should be started, in addition to the existing time-based batching.
This would allow safe batching while preventing cross-request context leakage.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions