socketry / multipart-post

Adds multipart POST capability to net/http
MIT License
293 stars 72 forks source link

Errno::EPIPE: Broken pipe #22

Closed kris-at-tout closed 3 years ago

kris-at-tout commented 11 years ago

gem version: 1.1.5

I have the following method (for reproducing)

require 'net/http/post/multipart'

def submit_file
  f = './lib/qa_monitoring/video_source/test.mp4'
  uri = URI.parse('https://api.tout.com/api/v1/touts')
  header = {"Authorization"=>"Bearer some_api_token", "Connection"=>"keep-alive",       "Accept"=>"application/json"}
  File.open(f) do |video|
    req = Net::HTTP::Post::Multipart.new(uri.path,
      {"file" => UploadIO.new(video, 'video/mp4', "video.mp4")},
      header)
    res = Net::HTTP.start(uri.host, uri.port) do |http|
      http.request(req)
    end
  end
  res
end

When I run this in irb, I get the following exception:

Errno::EPIPE: Broken pipe from /Users/kris/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/net/protocol.rb:199:in write' from /Users/kris/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/net/protocol.rb:199:inwrite0' from /Users/kris/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/net/protocol.rb:173:in block in write' from /Users/kris/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/net/protocol.rb:190:inwriting' from /Users/kris/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/net/protocol.rb:172:in write' from /Users/kris/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/net/http.rb:1955:insend_request_with_body_stream' from /Users/kris/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/net/http.rb:1921:in exec' from /Users/kris/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/net/http.rb:1317:inblock in transport_request' from /Users/kris/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/net/http.rb:1316:in catch' from /Users/kris/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/net/http.rb:1316:intransport_request' from /Users/kris/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/net/http.rb:1293:in request' from (irb):12:inblock (2 levels) in submit_file' from /Users/kris/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/net/http.rb:745:in start' from /Users/kris/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/net/http.rb:557:instart' from (irb):11:in block in submit_file' from (irb):7:inopen' from (irb):7:in `submit_file'

With the correct token, I can upload the same file via a REST client.

orodley commented 9 years ago

Hi @kris-at-tout, I'm getting the same error from a very similar snippet of code on the latest version of multipart-post. Did you ever manage to resolve this issue? Is there a workaround or something?

MaxPleaner commented 8 years ago

I get this error after switching from HTTP to SSL.

Errno::EPIPE: Broken pipe

[4] pry(#<RSpec::ExampleGroups::PerformanceTest>)> e.class
=> Errno::EPIPE
[5] pry(#<RSpec::ExampleGroups::PerformanceTest>)> e.backtrace
=> ["/home/max/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/net/http/generic_request.rb:206:in `write'",
 "/home/max/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/net/http/generic_request.rb:206:in `copy_stream'",
 "/home/max/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/net/http/generic_request.rb:206:in `send_request_with_body_stream'",
 "/home/max/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/net/http/generic_request.rb:123:in `exec'",
 "/home/max/.rbenv/versions/2.4.0-dev/lib/ruby/gems/2.4.0/gems/aws-sdk-core-2.2.9/lib/seahorse/client/net_http/patches.rb:27:in `block in new_transport_request'",
 "/home/max/.rbenv/versions/2.4.0-dev/lib/ruby/gems/2.4.0/gems/aws-sdk-core-2.2.9/lib/seahorse/client/net_http/patches.rb:26:in `catch'",
 "/home/max/.rbenv/versions/2.4.0-dev/lib/ruby/gems/2.4.0/gems/aws-sdk-core-2.2.9/lib/seahorse/client/net_http/patches.rb:26:in `new_transport_request'",
 "/home/max/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/net/http.rb:1407:in `request'"

...................... ETCETERA
MaxPleaner commented 8 years ago

I figured out how to solve my issue, which I also commented at https://github.com/nicksieger/multipart-post/issues/18

For me this was a HTTPS issue.

I split up the Net::HTTP.start method into two:

  1. my_request = Net::HTTP.new (which takes the same options as Net::HTTP.start)
  2. add the my_request.use_ssl = true option here (before starting the request)
  3. my_request.start { |http| ... etc }
ioquatix commented 7 years ago

Is this an issue with multipart-post or a general issue wiht usage of NET::HTTP? Can we close this?