Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-1819

SseBroadcaster.onClose() is not called when SseEventSink is closed or after client connection is closed.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Critical Critical
    • 4.0.0.Beta3
    • 4.0.0.Beta2, 3.5.0.Final
    • None
    • None

      SseBroadcaster has option to call onClose() callback:

      "Register a listener, which will be called when the SSE event output has been closed (either by client closing the connection or by calling SseEventSink.close() on the server side. "

      1) Client registers into broadcaster, opens the connection and sends requests for the event. Event is sent and broadcaster is closed with broadcaster.close() --> This works onClose() is called
      Test: https://github.com/resteasy/Resteasy/pull/1433/files#diff-9dd4255c27f8bcf5707772f9c25f6634R128

      2) Client registers into broadcaster, opens the connection and sends requests for the event.
      The broadcaster automatically closes the SseEventSink after message is sent.
      According to javadoc onClose() should be called when sinks closed. --> This doesn't work onClose() is not called

      @POST
          @Path("/startAndClose")
          public void broadcastAndClose(String message, @Context Sse sse, @Context SseEventSink sseEventSink) throws IOException {
              if (this.sseBroadcaster == null) {
                  throw new IllegalStateException("No Sse broadcaster created.");
              }
              this.sseBroadcaster.broadcast(sse.newEvent(message)).thenAccept((Object obj) -> {
                  sseEventSink.close();
              });
          }
      

      Test: https://github.com/resteasy/Resteasy/pull/1433/files#diff-9dd4255c27f8bcf5707772f9c25f6634R167

      3) Client registers into broadcaster, opens the connection and sends requests for the event. Event is send by server. After the client connection is closed check if the onClose()
      has been called. --> This doesn't work onClose() is not called
      Test: https://github.com/resteasy/Resteasy/pull/1433/files#diff-9dd4255c27f8bcf5707772f9c25f6634R205

              rhn-engineering-ema Jim Ma
              kanovotn Katerina Odabasi
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

                Created:
                Updated:
                Resolved: