2

I have an application that I have built using Node.js to deliver Server Sent Events. The application works fine on my local environment but now I have deployed it to AWS Elastic Beanstalk it is not working.

Having researched around it appears that the issue is explained in this post.

I have amended the configuration now, but I still have the issue that the EventSource cannot connect, and eventually times out. If I cURL to the end point it works as I would expect, but when I connect via JavaScript it fails.

This is my Nginx configuration:-

    upstream nodejs {
            server 127.0.0.1:8081;
            keepalive 256;
    }

    server {
            listen 8080;
            if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2})") {
                    set $year $1;
                    set $month $2;
                    set $day $3;
                    set $hour $4;
            }
            access_log /var/log/nginx/healthd/application.log.$year-$month-$day-$hour healthd;
            access_log  /var/log/nginx/access.log  main;


            location / {
                    proxy_pass  http://nodejs;
                    proxy_set_header   Connection "";
                    proxy_http_version 1.1;
                    chunked_transfer_encoding off;
                    proxy_buffering off;
                    proxy_cache off;
                    proxy_set_header        Host            $host;
                    proxy_set_header        X-Real-IP       $remote_addr;
                    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
            }

    gzip on;
    gzip_comp_level 4;
    gzip_types text/html text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;


    }

Does anyone have a clue why this is not working?

UPDATE To clarify, it actually does eventually connect, but then immediately loses connection and retries.

Community
  • 1
  • 1
baynezy
  • 6,493
  • 10
  • 48
  • 73
  • "curl to the endpoint" meaning directly to port 8080 on the instance? Or to the ELB? – Michael - sqlbot Sep 02 '15 at 23:20
  • @micheal I mean going via the ELB. So using the DNS created for Elastic Beanstalk. – baynezy Sep 03 '15 at 05:46
  • curl to the ELB *does* work, but not JavaScript? Is there an error in your code because of a static (hard coded) hostname or port, so that the js is sending to the wrong place? – Michael - sqlbot Sep 03 '15 at 09:59
  • @micheal. No, the JavaScript is calling the correct place. Please read my update to the question. – baynezy Sep 03 '15 at 10:23
  • 60 seconds seems like a suspiciously round number, doesn't it? https://aws.amazon.com/blogs/aws/elb-idle-timeout-control/ – Michael - sqlbot Sep 03 '15 at 11:32
  • I have increased the timeout to 180 seconds. It then times out somewhere between 60 and 80 seconds. If I reduce it to 30 seconds then it timesout on 30 seconds. Interestingly when it times-out it seems to deliver the pending messages – baynezy Sep 03 '15 at 12:25
  • 1
    Interesting but not entirely surprising... Elastic Load Balancer may not properly support EventSource, since -- even though it's (arguably) standard HTTP -- it's not quite proper request/response transactional like a "normal" HTTP request, because of the lingering connection. I will try to test this at some point and see if I get a similar result. – Michael - sqlbot Sep 03 '15 at 14:12

0 Answers0