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

SSE not working when app is behind Nginx. #73

Closed
Muddz opened this issue Mar 8, 2020 · 7 comments
Closed

SSE not working when app is behind Nginx. #73

Muddz opened this issue Mar 8, 2020 · 7 comments

Comments

@Muddz
Copy link

Muddz commented Mar 8, 2020

Has anyone managed to get their Go server app to work when its placed behind Nginx reverse-proxy setup in Ubuntu server?

I have followed these suggestions below without any success
For Server-Sent Events (SSE) what Nginx proxy configuration is appropriate?
EventSource / Server-Sent Events through Nginx

My POST and GET requests work as intended, but when the server app needs to publish something out to clients, the clients never receives anything.

@Muddz
Copy link
Author

Muddz commented Mar 8, 2020

According to one suggestion the app-server needs to add this header-value: X-Accel-Buffering: no;
with these headers here

@purehyperbole
Copy link
Member

purehyperbole commented Mar 9, 2020

Thanks for raising the issue. I've implemented #74 which should allow you to specify headers like:

s := sse.New()
s.Headers["X-Accel-Buffering"] = "no"
...

Please could you give it a try?

@Muddz
Copy link
Author

Muddz commented Mar 9, 2020

@purehyperbole It didn't do any difference

@Muddz
Copy link
Author

Muddz commented Mar 10, 2020

@purehyperbole Forget the previous comment! it did actually work and I discovered why by pure randomness. The key was to restart the Client when deploying and starting the new server-binary with the changes.

Why It only works when restarting the Client, is something I would like to know and I will do more testing and research into it.

I will also try to not include the X-Accel-Buffering header and try with pure Nginx configuration again where this time I restart the Client, so I have a full understanding of the issue

@purehyperbole
Copy link
Member

Thanks for testing. I'll merge that PR now 😄

@Muddz
Copy link
Author

Muddz commented Mar 10, 2020

So far I have learned this (For future, if anyone ends in the same probles):

  • Without any nginx SSE configurations but with X-Accel-Buffering: on header on the SSE-server it works! But exluding X-Accel-Buffering: on won't make SSE work, so one has to include it when no SSE specific nginx configuration is implemented

  • Without X-Accel-Buffering: on header but with Nginx SSE configuration it also works

  • The SSE Client will disconnect to the stream if the SSE server is not available for reasons like; a reboot, re-deployment or anything similar. When the SSE server is back online, the SSE client must reconnect to the stream again, this won't happend automatically and must be handled by the developer in the SSE client code. An example could be to listen for when the SSE Client disconnect and retry subscription to the stream for X amount of tries in Y amount of time:

	sseClient.OnDisconnect(func(c *sse.Client) {
		subscribeToSSE()
	})

@Muddz
Copy link
Author

Muddz commented Mar 10, 2020

@purehyperbole Everything in the library works as it should with regarding Nginx. If anyone in future have the same problem or similar, just point them to this issue.

@Muddz Muddz closed this as completed Mar 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants