inets/httpc bad match issue for 2 post requests

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

inets/httpc bad match issue for 2 post requests

Shawn Debnath
Hi there,

Wondering if anyone can shed some light on this issue I am seeing. 

I am trying to understand what may be causing **error:{badmatch,{error,socket_closed_remotely}} when using the same inets process to do 2 POST/PUT requests. The same code works just fine when issuing the same rest API calls to two separate inets processes or when issuing 2 GET requests to the same inets process. 

Using webmachine on the server side which is not reporting any errors, and looking at the WMTRACEs, it correctly returns HTTP 401 error, which is expected.

Test source and output can be found at: http://pastebin.com/9DFzxLps

Thanks,
Shawn


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: inets/httpc bad match issue for 2 post requests

Shawn Debnath
Interesting finding, after adding some debug printing to print out headers, now I can’t repro the issue:

  64     

  65 %% Invoke REST API calls via same inets/httpc processes

  66 same_inets_for_calls_test() ->

  67 

  68     inets:start(),

  69     

  70     BeginUrl = ?API_BASE ++ "begin_media_post",

  71     BeginH1 = [{"x-pryvy-authorization-status","Unknown"}],

  72     BeginHeaders = [{"x-pryvy-authorized-userid","100"} | BeginH1],

  73     {ok, {{_, BeginStatus, BeginResponseReason}, BeginResponseHeaders,

  74           BeginResponseBody}} =

  75         httpc:request(post, {BeginUrl, BeginHeaders, ?CONTENT_TYPE_JSON,

  76             ?SAMPLE_JSON_CONTENT}, [], []),

  77     io:format(standard_io, "resason: ~p~n headers: ~p~n body: ~p~n",

  78               [BeginResponseReason, BeginResponseHeaders, BeginResponseBody]),

  79     ?assertEqual(?HTTP_UNAUTH, BeginStatus),

  80     

  81     EndUrl = ?API_BASE ++ "end_media_post",

  82     EndH1 = [{"x-pryvy-authorization-status","Unknown"}],

  83     EndHeaders = [{"x-pryvy-authorized-userid","100"} | EndH1],

  84     {ok, {{_, EndStatus, EndResponseReason}, EndResponseHeaders,

  85           EndResponseBody}} =

  86         httpc:request(post, {EndUrl, EndHeaders, ?CONTENT_TYPE_JSON,

  87             ?SAMPLE_JSON_CONTENT}, [], []),

  88     io:format(standard_io, "resason: ~p~n headers: ~p~n body: ~p~n",

  89               [EndResponseReason, EndResponseHeaders, EndResponseBody]),

  90     ?assertEqual(?HTTP_UNAUTH, EndStatus),

  91     

  92     inets:stop().


Smells like the inets/httpc timing issue?

Thanks,
Shawn

From: Shawn Debnath
Date: Thursday, January 15, 2015 at 11:49 AM
To: Erlang Questions
Subject: [erlang-questions] inets/httpc bad match issue for 2 post requests

Hi there,

Wondering if anyone can shed some light on this issue I am seeing. 

I am trying to understand what may be causing **error:{badmatch,{error,socket_closed_remotely}} when using the same inets process to do 2 POST/PUT requests. The same code works just fine when issuing the same rest API calls to two separate inets processes or when issuing 2 GET requests to the same inets process. 

Using webmachine on the server side which is not reporting any errors, and looking at the WMTRACEs, it correctly returns HTTP 401 error, which is expected.

Test source and output can be found at: http://pastebin.com/9DFzxLps

Thanks,
Shawn


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: inets/httpc bad match issue for 2 post requests

Felix Gallo-2
In reply to this post by Shawn Debnath
httpc has some heisenbugs which I wish I had time to examine and try to fix.  The fact that a debug print statement makes the problem goes away suggests it's a race condition of some kind.  The smart money is on trying to use either hackney (https://github.com/benoitc/hackney) or one of the lhttpc forks (https://github.com/Cloven/lhttpc).

F.

On Thu, Jan 15, 2015 at 11:49 AM, Shawn Debnath <[hidden email]> wrote:
Hi there,

Wondering if anyone can shed some light on this issue I am seeing. 

I am trying to understand what may be causing **error:{badmatch,{error,socket_closed_remotely}} when using the same inets process to do 2 POST/PUT requests. The same code works just fine when issuing the same rest API calls to two separate inets processes or when issuing 2 GET requests to the same inets process. 

Using webmachine on the server side which is not reporting any errors, and looking at the WMTRACEs, it correctly returns HTTP 401 error, which is expected.

Test source and output can be found at: http://pastebin.com/9DFzxLps

Thanks,
Shawn


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions



_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: inets/httpc bad match issue for 2 post requests

Marc Worrell
My feeling is that the error is exactly what it says: the remote server closes the socket.
Adding a debug statement gives httpc the time to catch that close. Without the debug statement httpc will try to reuse the open connection to the server, at the moment the server is closing the connection.

Try to use HTTP/1.0 and an extra request header "Connection: close".
That might solve your problem.

Also check the server. Do you have a proxy in front of webmachine? Maybe check if the socket is closed after the first request?

- marc

Sent from my iPad

On 15 jan. 2015, at 22:05, Felix Gallo <[hidden email]> wrote:

httpc has some heisenbugs which I wish I had time to examine and try to fix.  The fact that a debug print statement makes the problem goes away suggests it's a race condition of some kind.  The smart money is on trying to use either hackney (https://github.com/benoitc/hackney) or one of the lhttpc forks (https://github.com/Cloven/lhttpc).

F.

On Thu, Jan 15, 2015 at 11:49 AM, Shawn Debnath <[hidden email]> wrote:
Hi there,

Wondering if anyone can shed some light on this issue I am seeing. 

I am trying to understand what may be causing **error:{badmatch,{error,socket_closed_remotely}} when using the same inets process to do 2 POST/PUT requests. The same code works just fine when issuing the same rest API calls to two separate inets processes or when issuing 2 GET requests to the same inets process. 

Using webmachine on the server side which is not reporting any errors, and looking at the WMTRACEs, it correctly returns HTTP 401 error, which is expected.

Test source and output can be found at: http://pastebin.com/9DFzxLps

Thanks,
Shawn


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: inets/httpc bad match issue for 2 post requests

Shawn Debnath
Well looks like that was the issue. Using just HTTP/1.0 without the "Connection: close" header does the trick as it forces the connection close. Tried with “Connection: keep-alive” header without the HTTP/1.0 option but that was a no-go as well.

Looks like its time to follow up with webmachine guys.

Thanks Marc and Felix.

From: Marc Worrell
Date: Thursday, January 15, 2015 at 1:37 PM
To: Felix Gallo
Cc: Shawn Debnath, Erlang Questions
Subject: Re: [erlang-questions] inets/httpc bad match issue for 2 post requests

My feeling is that the error is exactly what it says: the remote server closes the socket.
Adding a debug statement gives httpc the time to catch that close. Without the debug statement httpc will try to reuse the open connection to the server, at the moment the server is closing the connection.

Try to use HTTP/1.0 and an extra request header "Connection: close".
That might solve your problem.

Also check the server. Do you have a proxy in front of webmachine? Maybe check if the socket is closed after the first request?

- marc

Sent from my iPad

On 15 jan. 2015, at 22:05, Felix Gallo <[hidden email]> wrote:

httpc has some heisenbugs which I wish I had time to examine and try to fix.  The fact that a debug print statement makes the problem goes away suggests it's a race condition of some kind.  The smart money is on trying to use either hackney (https://github.com/benoitc/hackney) or one of the lhttpc forks (https://github.com/Cloven/lhttpc).

F.

On Thu, Jan 15, 2015 at 11:49 AM, Shawn Debnath <[hidden email]> wrote:
Hi there,

Wondering if anyone can shed some light on this issue I am seeing. 

I am trying to understand what may be causing **error:{badmatch,{error,socket_closed_remotely}} when using the same inets process to do 2 POST/PUT requests. The same code works just fine when issuing the same rest API calls to two separate inets processes or when issuing 2 GET requests to the same inets process. 

Using webmachine on the server side which is not reporting any errors, and looking at the WMTRACEs, it correctly returns HTTP 401 error, which is expected.

Test source and output can be found at: http://pastebin.com/9DFzxLps

Thanks,
Shawn


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions