spring-cloud / spring-cloud/spring-cloud-gateway

Server Sent Event response not flushed to client

Open
#1,550 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feedback-provided
Dominant language
Java
Stars
4.9k
Forks
3.5k
Avg merge
20h 57m
Merged PRs (30d)
8

Description

I am using spring cloud gateway v2.2.1.RELEASE to proxy to another microservice that is sending push updates via Server Sent Events. The problem is that when a client connects to the push server, the initial request hangs in status "pending", hence the client does not receive the "onopen" event that was sent from the push server. When push service sends its first message, the client gets both the new MessageEvent and the "onopen" event at once. It looks like that the gateway cannot properly flush the connection response from the push server until a second message arrives. Is there a way how to overcome this problem?

Here is how my configuration looks like:

spring:
  cloud:
    gateway:
      globalcors:
        cors-configurations:
          '[/**]':
            allowedMethods:
              - GET
              - POST
              - PUT
              - DELETE
              - OPTIONS
            allowHeaders: "*"
      routes:
        - id: sse
          uri: http://push-server
          predicates:
            - Path=/sse/**
          filters:
            - DedupeResponseHeader=Access-Control-Allow-Origin
            - SetResponseHeader=Access-Control-Allow-Credentials, true

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the /sse/** route with the shown Spring Cloud Gateway configuration and observe when the client's onopen and MessageEvent arrive. Trace the gateway's SSE response forwarding and flushing behavior; done means the initial response is flushed so onopen arrives before the first message, with a regression test if an appropriate existing test entry point is found.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring, spring-boot
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.