benoitc / hackney

simple HTTP client in Erlang
Other
1.34k stars 427 forks source link

ssl:recv/3 called with negative Length #722

Closed AnufrievDE closed 1 year ago

AnufrievDE commented 1 year ago

Hello,

I've faced this error, after updating hackney from 3f6d481 to master d6d075f.

According the traces collected within dbg:tpl(ssl, recv, 3, cx), it seems that ssl:recv is called from hackney_response:stream_body_recv/2 with wrong second argument: Length = -1:

(<0.31924.4357>) call ssl:recv({sslsocket,{gen_tcp,#Port<0.5997548>,tls_connection,undefined
},
           [<0.28413.4369>,<0.16905.4328>]},-1,5000) ({hackney_response,
                                                       stream_body_recv,2})
...
(<0.31924.4357>) exception_from {ssl,recv,3} {exit,{{{case_clause,[]},
        [{ssl_gen_statem,iovec_from_front,4,
                         [{file,"ssl_gen_statem.erl"},{line,1650}]},
         {ssl_gen_statem,read_application_data_bin,8,
                         [{file,"ssl_gen_statem.erl"},{line,1486}]},
         {ssl_gen_statem,passive_receive,4,
                         [{file,"ssl_gen_statem.erl"},{line,939}]},
         {gen_statem,loop_state_callback,11,
                     [{file,"gen_statem.erl"},{line,1426}]},
         {tls_connection,init,1,[{file,"tls_connection.erl"},{line,160}]},
         {proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,240}]}]},
       {gen_statem,call,[<0.28413.4369>,{recv,-1,5000},infinity]}}}

It probably related to this pull request.

nulian commented 1 year ago

@benoitc This bug is now released and breaks multiple requests for us with latest hackney.

tarzan commented 1 year ago

UP! This forced us to revert the update from hackney 1.8.2 back to 1.8.1 as well. Got this stacktrace in my Elixir app:

** (exit) exited in: :gen_statem.call(#PID<0.187518.0>, {:recv, -1, 5000}, :infinity)
    ** (EXIT) an exception was raised:
        ** (CaseClauseError) no case clause matching: []
            (ssl 11.0.1) ssl_gen_statem.erl:1715: :ssl_gen_statem.iovec_from_front/4
            (ssl 11.0.1) ssl_gen_statem.erl:1551: :ssl_gen_statem.read_application_data_bin/8
            (ssl 11.0.1) tls_gen_connection.erl:427: :tls_gen_connection.handle_protocol_record/3
            (stdlib 5.0.1) gen_statem.erl:1377: :gen_statem.loop_state_callback/11
            (ssl 11.0.1) tls_connection.erl:162: :tls_connection.init/1
            (stdlib 5.0.1) proc_lib.erl:241: :proc_lib.init_p_do_apply/3
    (stdlib 5.0.1) gen.erl:246: :gen.do_call/4
    (stdlib 5.0.1) gen_statem.erl:905: :gen_statem.call/3
    (ssl 11.0.1) ssl_gen_statem.erl:1319: :ssl_gen_statem.call/2
    (hackney 1.18.2) /home/runner/work/my_app/my_app/deps/hackney/src/hackney_response.erl:170: :hackney_response.stream_body_recv/2
    (hackney 1.18.2) /home/runner/work/my_app/my_app/deps/hackney/src/hackney_response.erl:312: :hackney_response.read_body/3
    (hackney 1.18.2) /home/runner/work/my_app/my_app/deps/hackney/src/hackney.erl:520: anonymous fn/2 in :hackney.body/2
    (httpoison 2.1.0) lib/httpoison/base.ex:888: HTTPoison.Base.request/6
    iex:13: (file)

I would strongly advise pulling this release

gmile commented 1 year ago

We had to downgrade from 1.8.2 to 1.8.1 due to this issue exactly.

seb3s commented 1 year ago

Same here, a downgrade from 1.8.2 to 1.8.1 was required

conradfr commented 1 year ago

Same here.

What I used in mix (if that helps anyone): {:hackney, git: "https://github.com/benoitc/hackney.git", tag: "1.18.1", override: true},

Also I can't understand why it's not catch in a try/catch when thrown inside a Httpoison.get! call ?

benoitc commented 1 year ago

isssue have been introduced in 5e74354a48653fe2456688f80c6bccb11143f6af . working on it.

benoitc commented 1 year ago

Please check #724 PR and let me know.

benoitc commented 1 year ago

fixed in maint.

AnufrievDE commented 1 year ago

Thanks! I'll check