Search code examples
ruby-on-railsrubytcpxmlhttprequestaction

What happens after a request to backend is cancelled by the client on Ruby on Rails?


I would like to know how ruby on rails requests works. What happens if I make a XHR request to an action of a controller on Ruby on Rails but before it finishes I reload the page, is the action cancelled or the action executes all method despite the client not receiving the response? I would like to know because from my method I am creating a tcp connection to another server to run some scripts but before the method finishes I have to close that connection manually, so I have detected that some tcp connections are kept opened, I think it is because sometimes the requests are cancelled before they finish and the part of the method where closes the tcp connections are not beign run.


Solution

  • If your client submitted request, and rails started processing that request, then it will continue even if client disconnects and does not wait for the response. In rails controller you will not see any error or anything that says client is disconnected.

    Also, if you are making HTTP call and don't care for response, I would recommend using some kind of async queue to make those requests (e.g. sidekiq). That way you could actually build some monitoring if you start caring about responses.