X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/b421d5c4754315cdd8b70b6bbea5b5f23fb425de..6f1c0e1dd16f53ce4fb7e8785a130e5f588500e5:/services/api/app/middlewares/rack_socket.rb diff --git a/services/api/app/middlewares/rack_socket.rb b/services/api/app/middlewares/rack_socket.rb index 892dbf5278..8f82e585df 100644 --- a/services/api/app/middlewares/rack_socket.rb +++ b/services/api/app/middlewares/rack_socket.rb @@ -19,12 +19,13 @@ class RackSocket # +app+ The next layer of the Rack stack. # # Accepts options: - # +:handler+ (Required) A class to handle new connections. Initialize will + # +:handler+ (Required) A class to handle new connections. #initialize will # call handler.new to create the actual handler instance object. When a new # websocket connection is established, #on_connect on the handler instance - # object to notify it about the connection. + # object will be called with the new connection. # - # +:mount+ The path for websocket connect requests, defaults to '/websocket'. + # +:mount+ The HTTP request path that will be recognized for websocket + # connect requests, defaults to '/websocket'. # # +:websocket_only+ If true, the server will only handle websocket requests, # and all other requests will result in an error. If false, unhandled @@ -68,7 +69,11 @@ class RackSocket def call env request = Rack::Request.new(env) if request.path_info == @endpoint and Faye::WebSocket.websocket?(env) - ws = Faye::WebSocket.new(env) + if @handler.overloaded? + return [503, {"Content-Type" => "text/plain"}, ["Too many connections, try again later."]] + end + + ws = Faye::WebSocket.new(env, nil, :ping => 30) # Notify handler about new connection @handler.on_connect ws