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

SSE and WS handlers get into an error handling loop on disconnect #1060

Closed
paulbakker opened this issue Sep 24, 2024 · 1 comment
Closed
Assignees
Labels
in: web Issues related to web handling type: bug A general bug
Milestone

Comments

@paulbakker
Copy link

When an SSE connection disconnects ungracefully, the next call of GraphQLSseHandler.writeResult will fail because of a broken pipe. This is expected.
However, the error handling in GraphQLSseHandler now gets into an infinite loop, where the error handling tries to write a message, fails again, and handles that failure the same way.
The publisher will never complete and keep emitting values.

I have a possible fix in this PR, which explicitly disposes the subscription on IOException.
Feel free to drop this PR for an alternative fix.
Note that I have not tested with Webflux, which has its own version of the SSEHandler.

To reproduce:

@Controller
public class SseDatafetcher {
    @SchemaMapping(typeName = "Subscription")
    public Flux<Long> example() {
        return Flux.interval(Duration.ofSeconds(1), Duration.ofSeconds(1))
                .doOnError(e -> System.out.println("Error"))
                .doOnCancel(() -> System.out.println("Cancel"))
                .onErrorComplete();
    }
}

And then curl:

 curl -X POST -N  -H "Content-Type: application/json" -H "Accept: text/event-stream" -d '{"query": "subscription { example }"}' http://localhost:8080/graphql  -i

This will start printing results. The error loop happens when the curl is cmnd-c-ed.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 24, 2024
@bclozel bclozel self-assigned this Sep 26, 2024
@bclozel bclozel added type: bug A general bug in: web Issues related to web handling and removed status: waiting-for-triage An issue we've not yet triaged labels Sep 26, 2024
@bclozel bclozel added this to the 1.3.3 milestone Sep 26, 2024
@bclozel bclozel changed the title SSE handler gets into an error handling loop on disconnect SSE and WS handlers get into an error handling loop on disconnect Sep 26, 2024
@bclozel
Copy link
Member

bclozel commented Sep 26, 2024

Thanks for catching this @paulbakker !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues related to web handling type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants