Skip to content

error reading from socket: Could not parse data #589

@Bonias

Description

@Bonias

Hi,

I'm investigating an error that is raised when making http request to one of the remote APIs. I don't want to post that request as there are some secrets used, but I think I was able to create minimal reproducible example:

require 'socket'

Thread.new do
  server = TCPServer.open(3000)

  client_connection = server.accept

  body_1 = "HTTP/1.1 200 OK\r\nContent-Length: 2\r\nContent-Type: application/json\r\nMyHeader"
  body_2 = ": val\r\n\r\n{}"

  client_connection.write(body_1)
  client_connection.write(body_2)
end

require 'http'
HTTP.get('http://localhost:3000/')

Here is the error that is returned:

Traceback (most recent call last):
       11: from /home/bonias/.rvm/rubies/ruby-2.6.5/bin/irb:23:in `<main>'
       10: from /home/bonias/.rvm/rubies/ruby-2.6.5/bin/irb:23:in `load'
        9: from /home/bonias/.rvm/rubies/ruby-2.6.5/lib/ruby/gems/2.6.0/gems/irb-1.0.0/exe/irb:11:in `<top (required)>'
        8: from (irb):16
        7: from /home/bonias/.rvm/gems/ruby-2.6.5/gems/http-5.0.0.pre/lib/http/chainable.rb:20:in `get'
        6: from /home/bonias/.rvm/gems/ruby-2.6.5/gems/http-5.0.0.pre/lib/http/chainable.rb:75:in `request'
        5: from /home/bonias/.rvm/gems/ruby-2.6.5/gems/http-5.0.0.pre/lib/http/client.rb:31:in `request'
        4: from /home/bonias/.rvm/gems/ruby-2.6.5/gems/http-5.0.0.pre/lib/http/client.rb:75:in `perform'
        3: from /home/bonias/.rvm/gems/ruby-2.6.5/gems/http-5.0.0.pre/lib/http/connection.rb:103:in `read_headers!'
        2: from /home/bonias/.rvm/gems/ruby-2.6.5/gems/http-5.0.0.pre/lib/http/connection.rb:217:in `read_more'
        1: from /home/bonias/.rvm/gems/ruby-2.6.5/gems/http-5.0.0.pre/lib/http/response/parser.rb:31:in `add'
HTTP::ConnectionError (error reading from socket: Could not parse data)

Error is not returned when using http version <= 4.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions