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

Add "X-Accel-Buffering: no" header to improve subscriptions with reverse proxy #7084

Open
zshall opened this issue Apr 30, 2024 · 0 comments
Labels
🎉 enhancement New feature or request 🌶️ hot chocolate Next Next up on the backlog.

Comments

@zshall
Copy link

zshall commented Apr 30, 2024

Product

Hot Chocolate

Is your feature request related to a problem?

I've personally encountered this issue but I also saw others are experiencing it so I'm opening an issue.

The issue is that when you use Server-Sent Events in Subscriptions in Hot Chocolate and your server is running behind a reverse proxy such as Azure Application Gateway that uses response buffering, you either never receive subscription events or the events are delayed. The reason for this is because Hot Chocolate's endpoints don't add a specific header: X-Accel-Buffering set to no, which configures the reverse proxy to send data as its received rather than waiting for the entire (potentially endless) response.

I figured this out based off of this StackOverflow question but there isn't a lot of information about it that I've been able to find.

The solution you'd like

The solution I used to fix this problem was to add a middleware to detect whether we're serving GraphQL requests and to add this header:

app.Use((ctx, next) => {
    if (ctx.Request.Path.ToString().Contains("/graphql")) {
        var headers = ctx.Response.Headers;
        headers.Append("X-Accel-Buffering", "no");
    }
    return next();
});

This works, but I had to do it this way because I couldn't find a way to configure the headers that Hot Chocolate sends to include the header. It'd be advantageous if this was an option built into Hot Chocolate and documented so that anyone else using a setup like this can benefit.

@zshall zshall added the 🎉 enhancement New feature or request label Apr 30, 2024
@michaelstaib michaelstaib added the Next Next up on the backlog. label May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎉 enhancement New feature or request 🌶️ hot chocolate Next Next up on the backlog.
Projects
None yet
Development

No branches or pull requests

2 participants