1

I am using Amazon Elastic Beanstalk (Nginx 1.4.2 + Passenger 4.0.20 + Ruby 1.9.3) to deploy a sinatra app that uses Server Sent Events. Everything works perfectly on local machine using thin. On AWS Elastic Beanstalk though, the connection gets dropped after milliseconds.

server code look like this:

get '/stream', provides: 'text/event-stream' do
  response.headers['X-Accel-Buffering'] = 'no'
  stream :keep_open do |out|
    settings.connections << out
    out.callback { settings.connections.delete(out) }
  end
end

On the server log I see a connection timeout:

2013/11/20 19:45:46 [info] 9716#0: *35 client closed connection while waiting for request, client: xxx.xxx.xxx.xxx, server: 0.0.0.0:80

Tried the nginx configuration suggested here (EventSource / Server-Sent Events through Nginx) under the server block and although the header response changes, it is not yet working.

(I had to set X-Accell-Buffering on Nginx file as well, because it would not take the setting set in server code with sinatra)

Response header looks something like this:

HTTP/1.1 200 OK
Content-Type: text/event-stream;charset=utf-8
Date: Wed, 20 Nov 2013 20:03:06 GMT
Server: nginx/1.4.2 + Phusion Passenger 4.0.20
Status: 200 OK
X-Accel-Buffering: no
X-Content-Type-Options: nosniff
X-Powered-By: Phusion Passenger 4.0.20
transfer-encoding: chunked
Connection: keep-alive

Any ideas?

Thanks in advance.

Community
  • 1
  • 1
buzali
  • 802
  • 1
  • 6
  • 12

1 Answers1

1

Did you try the suggestion in the comments? those seem more logical to me

proxy_buffering off;
proxy_cache off;

Also please share your current config if those don't work.

Mohammad AbuShady
  • 40,884
  • 11
  • 78
  • 89
  • I tried this and it didn't work. I ended up discarding Elastic Beanstalk and ngnix by using a regular EC2 instance. – buzali Jan 06 '14 at 19:36
  • I have similar issue, I have a Flask app that has a stream reading from a database, it works fine on local machine, but on Beanstalk it sometimes work sometimes don't without me changing anything. Really confused! – Logan Yang Aug 02 '19 at 01:27