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

TaskExecutors.IO is not honored with Server-Sent Event when client is disconnected (blocking netty event loop) #11541

Open
fhussonnois opened this issue Jan 26, 2025 · 0 comments
Labels
status: under consideration The issue is being considered, but has not been accepted yet

Comments

@fhussonnois
Copy link

Expected Behavior

The @ExecuteOn(TaskExecutors.IO) annotation should be honored even in the case a Server-Sent Event Flux is terminated proactively by Micronaut (i.e., when client is disconnected)

Actual Behaviour

Using Server-Sent-Event, when the client disconnects, then the Flux is terminated by Micronaut, any doFinally operation will be executed by the netty event loop even if the method is annotated by @ExecuteOn(TaskExecutors.IO).

As the method is annotated as blocking I would expect the flux to be published on io-executors before being competed.

Steps To Reproduce

Reproducer

  • Create an SSE endpoint like below:
@Controller("/test")
@Secured(SecurityRule.IS_ANONYMOUS)
public class BlockingSseController {

    @ExecuteOn(TaskExecutors.IO)
    @Get(uri = "/sse", produces = MediaType.TEXT_EVENT_STREAM)
    public Flux<Event<String>> sse() {
        return Flux.<Event<String>>create(emitter -> {
                // Emit next
                for (int i = 0; i < 10; i++) {
                    System.out.printf("[%s] emitter%n", Thread.currentThread());
                    emitter.next(Event.of("data-"+i));
                    doSleep(1000);
                }
                // Complete
                emitter.complete();
            }, FluxSink.OverflowStrategy.BUFFER)
            .doFinally(ignored -> {
                 System.out.printf("[%s] doFinally%n", Thread.currentThread());
                 doSleep(1000000000000L);
            });
    }
  • Request the endpoint (For: http://localhost:8080/api/v1/test/sse)
  • Interrupt the connection before the Flux is completed

logs:

[Thread[#252,io-executor-thread-4,5,main]] emitter
...
[Thread[#252,io-executor-thread-4,5,main]] emitter
[Thread[#206,default-nioEventLoopGroup-1-4,5,main]] doFinally

When the Flux is completed by the emitter:

logs:

[Thread[#218,io-executor-thread-3,5,main]] emitter
...
[Thread[#218,io-executor-thread-3,5,main]] emitter
[Thread[#218,io-executor-thread-3,5,main]] doFinally

Environment Information

  • Linux
  • Java Version: 21

Example Application

No response

Version

4.7.3

@fhussonnois fhussonnois changed the title TaskExecutors.IO is not honored with Server-Sent Event on when client is disconnected (blocking netty event loop) TaskExecutors.IO is not honored with Server-Sent Event when client is disconnected (blocking netty event loop) Jan 26, 2025
@graemerocher graemerocher added the status: under consideration The issue is being considered, but has not been accepted yet label Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: under consideration The issue is being considered, but has not been accepted yet
Projects
None yet
Development

No branches or pull requests

2 participants