Skip to content

Inconsistency in SseEmitter.onCompletion() behavior between Spring 6.2.3 and 6.2.5 #34762

Closed
@jrpedrianes

Description

@jrpedrianes

Summary

There is an inconsistency in the invocation behaviour of the SseEmitter.onCompletion() callback between Spring Framework versions 6.2.3 and 6.2.5. Previously, calling emitter.complete() would immediately trigger the callback registered via onCompletion(). However, starting with Spring Framework 6.2.5 (used in Spring Boot 3.4), this callback no longer appears to execute after complete() method is invoqued.

Current Behaviour

When using Spring Boot 3.4 (with Spring Framework 6.2.5), calling emitter.complete() does not cause an immediate invocation of the onCompletion() callback. This behaviour differs from that in Spring Boot 3.3 (with Spring Framework 6.2.3), where emitter.complete() immediately triggered the callback.

Expected behaviour

The expected behaviour is that calling emitter.complete() should trigger the onCompletion() callback immediately, just as it did in Spring Boot 3.3 (Spring Framework 6.2.3).

Steps to Reproduce

You can reproduce the issue with the following setup:

  1. Implement the controller below in your application:
    @RestController
    public class SseController {
    
        @GetMapping("/sse")
        public SseEmitter handleSse() {
            SseEmitter emitter = new SseEmitter();
    
            emitter.onCompletion(() -> {
                System.out.println("onCompletion callback executed");
            });
    
            ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
            scheduler.schedule(() -> {
                emitter.complete();
            }, 1, TimeUnit.SECONDS);
    
            return emitter;
        }
    }
  2. Run the application with Spring Boot 3.3 (which uses Spring Framework 6.2.3) and observe that the log shows "onCompletion callback executed" immediately after calling complete().
  3. Update the application to Spring Boot 3.4 (with Spring Framework 6.2.5) and notice that the callback is not executed immediately.

Additional Notes

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: regressionA bug that is also a regression

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions