Calling EventSource for ActionController :: Pending Pending

I am currently working on a site that has the following capabilities:

  • live chat
  • some statistics
  • some forms

I am using: Rails 4 + Puma + Nginx

I am using ActionController :: Live and created an action with an event that is called on page load and has listeners attached to it that listen for chat messages or changes in statistics.

def events
response.headers["Content-Type"] = "text/event-stream"

sse   = ServerEvent.new(response.stream)
redis = Redis.new

# the safe_write method is the implementation of a workaround for the problem stated on
# http://evaleverything.com/2013/09/07/response-streams-with-rails-4-and-redis
sse.safe_write do
  redis.psubscribe("redis-foobar-key*") do |on|
    on.pmessage do |pattern, event, data|
      sse.write(data, { event: event})
    end
  end
end
rescue IOError
  puts "Stream Closed"
ensure
  puts "closing all threads and connections\n"
  redis.quit
  sse.close
end

      

The problem I'm running into is this: sometimes everything goes right on page load, I can fire the eventource and handle events correctly, but sometimes the eventsource request stays pending t returns any error.

I have made successful attempts through:

  • chrome + windows
  • chrome + macosx (computer A)
  • firefox + macosx (computer A)

And made unsuccessful attempts through:

  • chrome + ubuntu (behind a proxy)
  • firefox + ubuntu (behind a proxy)
  • chrome-macosx (computer B)
  • firefox + macosx (computer B)

I am using nginx but dont think this is the problem, nevertheless, here is my config

upstream bar {
  server foo.com:9292;
}

server {
  listen 80;
  server_name foo.com megafoo.com;
  root /(...)/public;

  location / {
    proxy_pass http://bar;


    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    proxy_set_header Connection '';
    proxy_http_version 1.1;
    chunked_transfer_encoding off;

    proxy_buffering off;
    proxy_cache off;

    if (-f $request_filename) {
     break;
    }
  }

  location ~* ^/assets/ {
    # Per RFC2616 - 1 year maximum expiry
    expires 1y;
    add_header Cache-Control public;

    # Some browsers still send conditional-GET requests if there a
    # Last-Modified header or an ETag header even if they haven't
    # reached the expiry date sent in the Expires header.
    add_header Last-Modified "";
    add_header ETag "";
    break;
  }
}

      

+3


source to share


1 answer


it looks like the antivirus was blocking the connection, preventing it from completing successfully



+3


source







All Articles