Spring Web-Flux Server Sent Events is not working when using IP for local and remote calls

1.4k Views Asked by At

I have two simple controllers:

@GetMapping(value = "/simple-get")
public String simpleGet() {
    return "simple Get";

}

@GetMapping(path = "/stream-flux", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<String> streamFlux() {
    return Flux.interval(Duration.ofSeconds(2))
            .map(sequence -> "Flux - " + LocalTime.now().toString());
}

When calling the first one, it works as expected (locally and remotely using an ip of a different machine). But when calling the second one, it works as expected using localhost e.g.: http://localhost:65465/stream-flux but it does not work remotely when deployed to a different machine using its ip. I even checked and it does not work locally when using 127.0.0.1 which is very strange.. all things that does not work with web-flux, works as expected with the simple-get API so I rule out connection problems..Couldn't find anything about it anywhere.. would appreciate any thoughts on this.

1

There are 1 best solutions below

1
On

Thanks for everyone who were interested in helping. After additional investigation we have found the RC and it actually has nothing to do with the code/Spring-web-flux. When using ip address or calling it remotely, the request was stuck on pending until it reached the timeout defined on the server. On a windows machine using netstat -ano | findstr 8080 on the cmd We were able to find the ports being used and their status. When using local host, the first call to the api assigns an additional port to establish a connection that would remain open for later Server Sent Events and we can see the PID of the process that is listening to that new port is the browser. When using ip address. same exact thing is happening but the process that is now listening to the new port is in fact the anti-virus. Sophos antivirus has a feature of web-protection and it treats SSE as a malicious download thread so it waits for the http response to arrive in order to scan it, in SSE it never arrives as long as the connection is open.

more details:

https://community.sophos.com/free-antivirus-tools-for-desktops/f/discussions/5750/sophos-av-blocks-server-sent-events-sse-on-mac-os-x-yosemite

JavaScript EventSource SSE not firing in browser

Using https should solved the problem.

Thanks