5

I am working on a Redmine plugin and I created a method where I'm sending 2 HTTP POST requests to attach a file to a document.

After executing the first request, I get a Timeout::Error (Timeout::Error) although the request has been successfully done, here is the error code from Webrick

Timeout::Error (Timeout::Error): 
/usr/local/lib/ruby/1.9.1/net/protocol.rb:146:in `rescue in rbuf_fill' 
/usr/local/lib/ruby/1.9.1/net/protocol.rb:140:in `rbuf_fill' 
/usr/local/lib/ruby/1.9.1/net/protocol.rb:122:in `readuntil' 
/usr/local/lib/ruby/1.9.1/net/protocol.rb:132:in `readline' 
/usr/local/lib/ruby/1.9.1/net/http.rb:2562:in `read_status_line' 
/usr/local/lib/ruby/1.9.1/net/http.rb:2551:in `read_new' 
/usr/local/lib/ruby/1.9.1/net/http.rb:1319:in `block in transport_request'  
/usr/local/lib/ruby/1.9.1/net/http.rb:1316:in `catch' 
/usr/local/lib/ruby/1.9.1/net/http.rb:1316:in `transport_request' 
/usr/local/lib/ruby/1.9.1/net/http.rb:1293:in `request' rest-client (1.6.7) lib/restclient/net_http_ext.rb:51:in `request' 
/usr/local/lib/ruby/1.9.1/net/http.rb:1286:in `block in request' 
/usr/local/lib/ruby/1.9.1/net/http.rb:745:in `start' 
/usr/local/lib/ruby/1.9.1/net/http.rb:1284:in `request'
...
...
Started POST "/uploads.json?attachment_id=1&filename=testFile.txt" for <server_IP_address> at 2014-04-02 09:15:28 +0200 
Processing by AttachmentsController#upload as JSON 
Parameters: {"attachment_id"=>"1", "filename"=>"testFile.txt"} 
Current user: <user> (id=3) 
Saving attachment '/home/user/Redmine/redmine-2.4.2/files/2014/04/140402091528_testFile.txt' (72 bytes) 
Rendered attachments/upload.api.rsb (1.7ms) 
Completed 201 Created in 87.9ms (Views: 7.9ms | ActiveRecord: 11.4ms)

You can see that I get a 201 Status in the response thus it worked but I have this Timeout error and the execution stops there.

Here is my code:

uri = URI.parse("http://<server_IP_address>:3000/uploads.json")

http = Net::HTTP.new(uri.host, uri.port)
@file = File.new("/home/testFile.txt")
@csrfToken = session[:_csrf_token]

request = Net::HTTP::Post.new(@uri.path+"?attachment_id=1&filename=testFile.txt", initheader = {'Content-Type' => "application/octet-stream", 'X-CSRF-Token' => @csrfToken, 'X-Redmine-API-Key' => "my_key"})
request.body = @file.read
@response = http.request(request)

@upToken = @response.body

@secondResponse = RestClient.post 'http://<server_IP_address>:3000/documents/150/add_attachment', {:multipart => true, :utf8 => "\u2713", :authenticity_token => @csrfToken, :attachment => { "1" => {:filename => "testFile.txt", :description => "Dropbox blabla", :token => @upToken}}, :commit => "Add"}, :'X-Redmine-API-Key' => "mykey"

I also tried with Apache Web server and the first request works perfectly, I only get this problem with Redmine running on Webrick server.

Do you have an idea where does this error come from and how I could get rid of it?

Shredator
  • 940
  • 3
  • 17
  • 32
  • Wish I could help -- the only thing I can say is the error will be tied to WebBrick, but other than that I'll need to learn about it – Richard Peck Apr 02 '14 at 08:07
  • Network time out error refers to server took more time to process your request than assigned timeout interval. There should be a config option to specify it. In unicorn you can specify timeout interval to the values you want. However having longer timeout interval means your app is slow to the user. I would recommend you to put the processing of these kinds of request to background jobs. – Mr. Bless Apr 11 '14 at 14:55
  • Good idea to put these requests in background, I'm gonna try this. – Shredator Apr 15 '14 at 08:34

1 Answers1

0

What you have to do is that you need to change the request timeout value in webrick server, in order to do so check the answer of this question: how to set request timeout in rails ( thin or webrick server)

  • I saw this post and tried to change this value but it didn't solve the problem. This is a "small" request which is executed pretty fast so that shouldn't be a problem. Moreover, when it's running on Apache Web server it took less than 10s and it's working well. – Shredator Apr 15 '14 at 08:33