[erlang-questions] Mixing of http:request response

I-T <>
Thu May 9 17:20:02 CEST 2013


I was experiencing an interesting issue. I need my mochiweb view, to post
to another service and proxy the response. That happens within a receive
block which looks like:-

                        ?INFO("Posting to TransactionID ~s Payload ~s ~n",
[TraceTransactionId, Temp]),
                        case http:request(post, {Url, [],
"application/x-www-form-urlencoded", Temp}, [], []) of
                            {_, {_,_,JsonData}} ->
                                ?INFO("Response Data TransactionID ~s
Response ~s ~n", [TraceTransactionId, JsonData]),
                                success(Req, "text/plain", JsonData);
                            _ ->
                                ?INFO("Error Posting to Adam ~n", []),
                                error(Req, 500, "Problem Getting Data")
                        end

Then in concurrent scenarios, sometimes the response of one will be logged
against the request of another while the TransactionID would remain the
same.

If However I swap this block with a simple curl command line executor,
everything seems to work and the problem cant be repro'ed

                        CurlCommand = io_lib:format("curl -s -d \"~s\" ~s",
[Temp, Url]),
                        ?INFO("Executing Curl Command ~s Curl ~s",
[TraceTransactionId, CurlCommand]),
                        CurlResponse = os:cmd(CurlCommand),
                        ?INFO("Curl Response ~s Curl ~s",
[TraceTransactionId, CurlResponse]),
                        JsonData = string:strip(CurlResponse),
                        success(Req, "text/plain", JsonData);


This seems to work fine and I dont experience the concurrency issue. It
should default to synchronous but in 10% of the cases it seems to mix the
responses.

My Questions
1) Am I using the inets http client the correct way?
2) If so then why does the curl wrapper work?
3) How can I investigate this further?

Best Regards,

Iqbal Talaat Bhatti

"If we did all the things we are capable of doing, we would literally
astound ourselves." - Thomas Edison
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130509/fb1e27f7/attachment.html>


More information about the erlang-questions mailing list