kamal
kamal copied to clipboard
Server-Sent Events not working?
I have a Django app that works just fine locally and on render.com (I'm porting it to use Kamal 2 and Hetzner), but when deployed via Kamal, the SSE part of the app seems to just stop working. Is there anything extra I need to do — and can't seem to locate in the docs — in order to get SSE working?
The response headers for the text/event-stream request are empty. When I run curl --no-buffer 'http://localhost:9000/events/f01657c8-5d4a-44f7-b2dd-facbea21efc9/' I get the expected response with event: stream-open, then keep-alives and so on. But running the same cURL command against the Kamal-deployed app endpoint does not return anything, it just seems to hang.
And relatedly, I can't turn off response buffering in the proxy configuration. Setting response buffering to false results in
ERROR (SSHKit::Command::Failed): Exception while executing on host <ip>: docker exit status: 1
docker stdout: Nothing written
docker stderr: bash: warning: setlocale: LC_ALL: cannot change locale (en_GB.UTF-8)
Error: accepts 1 arg(s), received 2
Seems to be related to https://github.com/basecamp/kamal/issues/956?
Thanks @karls!
I've raised https://github.com/basecamp/kamal/pull/1018 to fix the buffering arguments. I guess it may be that disabling the buffering is what's needed to fix your issue with SSE?
Thanks @djmb! I suspect so, yes.
BTW I'm using django-eventstream, which sets the X-Accel-Buffering response header, which some proxies seem to honour. AFAICT that header is used specifically for SSE, streaming responses etc in order to tell the proxy not to buffer the response. Is this something kamal-proxy could/should support?
Yes, definitely something it should support - I've raised https://github.com/basecamp/kamal-proxy/issues/34 to track 👍
@karls this is fixed in the proxy now, so SSE responses will work properly in the next release. Thank for reporting the issue!
This is great! Thank you, @kevinmcconnell! 👍🏻
Going to close this as both issues mentioned in my initial message have been addressed in #1018 and basecamp/kamal-proxy#34.