Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pattern matching error. #113

Closed
aklaim opened this issue Jul 1, 2014 · 0 comments
Closed

Pattern matching error. #113

aklaim opened this issue Jul 1, 2014 · 0 comments

Comments

@aklaim
Copy link

aklaim commented Jul 1, 2014

During a call of hackney_socks5:do_handshake, in part:

case gen_tcp:recv(Socket, 2, ?TIMEOUT) of
                {ok, << 5, 0 >>} ->
                    do_connection(Socket, Host, Port);
                Error ->
                    Error
            end;

gen_tcp:recv can return {ok, SomeValue} which is counted as an error and returns up the call stack as a {ok, SomeValue}.

The problem is that hackney:connect/5 in the part:

     case maybe_proxy(Transport, Host, Port, Options) of
        {ok, Ref, AbsolutePath} ->
            Request = make_request(Method, URL, Headers, Body,
                                   Options, AbsolutePath),
            send_request(Ref, Request);
        {ok, Ref} ->
            Request = make_request(Method, URL, Headers, Body, Options, false),
            send_request(Ref, Request);
        Error ->
            Error
    end;

is waiting for {ok, Ref} in case of success. Because of this, the value of which was return by gen_tcp:recv will be considered as valid and its further use will lead to error.

The error occurs in the case of using socks5 proxy which does not work properly, but at the same time available for gen_tcp:send.

I attach an image with debugging this error. It is hard to understand where is the problem because of long call stack.
bug

It can be fixed by adding:

 {ok, _Reply} ->
                  {error, unknown_reply};

in hackney_socks5:do_handshake:

   case gen_tcp:recv(Socket, 2, ?TIMEOUT) of
                {ok, << 5, 0 >>} ->
                    do_connection(Socket, Host, Port);
                {ok, _Reply} ->
                  {error, unknown_reply};   %% FIX
                Error ->
                    Error
            end;
@benoitc benoitc closed this as completed in 05e5e1e Jul 8, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant