Webrick / Rails - timeout error after sending POST request

I am working on a Redmine plugin and I created a method in which I send 2 HTTP POST requests to attach a file to a document.

After executing the first request, I get Timeout::Error (Timeout::Error), although the request was successful, here is the Webrick error code

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 received status 201 in the response, so it worked, but I have this timeout error, and 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 the Apache web server and the first request works fine, I only get this problem with Redmine running on the Webrick server.

Do you have an idea where this error came from, and how can I get rid of it?

+4
1

, , - webrick, , : - rails ( webrick-)

0

Source: https://habr.com/ru/post/1534599/


All Articles