0

I am having some kind of a bug, where after a 30 second timeout, the request seem to be received again by the server.

the flow:

the user enters several (or many) image urls to a text field which is sent to the server

sources = "mysite.com/1.jpg mysite.com/2.jpg mysite.com/1.jpg"

the server splits by white space and for every url create a new image

sources.split(" ").map do |url|
  Photo.create(source: url)
end

Photo is a model with paperclip attachment called img, and a source column an after_action exists with self.img_remote_url = self.source to add the source as a source to the attachment

note that I am not using background processing here

The problem started today, but a few days ago it worked fine. It occurs when the number of images causes the request to timeout (since the processing takes more than 30 seconds). Usually, it would just keep processing the images on the server. Now when the timeout occurs, seeing from the logs, the request seems to have been received again which processes all the files again.

At the point, (using puma), the second thread starts to work, but then again, reach a timeout.. This continues until all the threads, processes, and dynos are full and can't receive anymore requests. Which then the processing complete, having multiple photos created and very upset programmer (me)

It is unclear to me why the request would be resent to the server. It is not a client-side issue, since the duplication doesn't occur immediately, and by the logs it is right when the timeout error occurs (H12)

I am using puma 2.9.1, ruby 2.1.3, rails 4.1.6, heroku cedar, and latest paperclip.

Is there anything that causes a redo of a request when timeout? How can I debug this? Could it be a bug in heroku routing mechanism yet to be discovered?

Nick Ginanto
  • 31,090
  • 47
  • 134
  • 244
  • How do you exclude the possibility of a client doing a re-request? I do not understand the reasoning with "immediately". You could try by looking in the browsers development network graph (usually F12), or using curl/wget. – Felix Sep 22 '14 at 06:17
  • First, I logged a sentence at the beginning of the controller's action, and it only appears once. Second, the 2nd request happens exactly when the timeout occurs, not before. If I add less photos and a timeout doesn't occur, this problem doesn't happen. And also, I don't see another request from the browser – Nick Ginanto Sep 22 '14 at 07:21
  • The request may have not be received twice, but its data is. The same exact POST goes back to the server (bypassing the controller) – Nick Ginanto Sep 22 '14 at 07:22
  • Okay, sorry to not be able to help you. You could try a different handler (thin, webrick) to nail down the thing a bit. – Felix Sep 22 '14 at 08:10
  • @NickGinanto Did you get a solution for this? I'm facing similar issue in express application – Jijil Kakkadathu Jan 23 '19 at 15:35
  • @JijilKakkadathu sorry I dont remember what I did here. Probably, since the image processing was not in a background process, I moved it to a background processor since it was easier than to go force the issue to be resolved. If you are in express, by increasing the timeout you should be ok, since it would work async. Still you might be better off using something like bull to work on your files in a separate process – Nick Ginanto Jan 23 '19 at 16:55

0 Answers0