[erlang-questions] making http client close connections

Oscar Hellström oscar@REDACTED
Tue Jun 9 19:40:36 CEST 2009


Hi Joel,

I think someone else pointed out two ways of doing this with inets. One
is to specify a version < 1.1, the other is to include the Connection:
close header. However, as mentioned before, I wouldn't recommend using
the inets http client for any serious work.

Cheers

Joel Reymont wrote:
> I've been banging my head against this all day today, to no avail.
>
> I have a keep-alive connection that must be closed from the client
> side but I cannot for the life of me figure out how to do it!!!
>
> I start the client with a profile name
>
>     inets:start(),
>     Profile = list_to_atom(pid_to_list(self())),
>     {ok, Pid} = inets:start(httpc, [{profile, Profile}]),
>
> I supply the profile name to http:request/5
>
>     {ok, Ref} = http:request(get, {URI2, []}, [], [{sync, false}],
> Profile),
>
> When the time comes to shut down the connection, I use the profile
> name and cancel the request, just in case. I tried shutting down using
> the pid returned by inets:start/2 but it didn't do the trick.
>
>     http:cancel_request(State#state.ref),
>     ok = inets:stop(httpc, State#state.profile),
>
> Assuming that my profile name is 'httpc_manager_<0.83.0>', I see the
> profile being shut down (my debugging output)
>
>     Stopping <0.96.0>, ref: #Ref<0.0.0.203>
>
> Still, I see the following at the shell prompt, telling me that
> there's still a connection to the server. Note that the profile name
> is correct!
>
> How in the world do I make http client close all sessions belonging to
> the profile!?
>
>     Thanks, Joel
>
> ---
>
> =ERROR REPORT==== 9-Jun-2009::18:02:58 ===
> ** Generic server <0.98.0> terminating
> ** Last message in was {tcp,#Port<0.3069>,
>                             <<"HTTP/1.1 200 OK\r\nContent-Length:
> 62\r\n\r\nXXXXX.instance.script_tag_connection().data_received(\"ping\");">>}
>
> ** When Server state == {state,undefined,
>                             {tcp_session,
>                                 {{"localhost",8081},<0.98.0>},
>                                 false,http,#Port<0.3069>,1,keep_alive},
>                             undefined,undefined,undefined,undefined,
>                             {[],[]},
>                             {[],[]},
>                             keep_alive,[],nolimit,nolimit,
>                             {options,
>                                 {undefined,[]},
>                                 0,2,5,120000,2,disabled,enabled,false},
>                             {timers,[],#Ref<0.0.0.227>},
>                             'httpc_manager_<0.83.0>',undefined}
> ** Reason for termination ==
> ** {function_clause,
>        [{httpc_handler,handle_info,
>             [{tcp,#Port<0.3069>,
>                  <<"HTTP/1.1 200 OK\r\nContent-Length:
> 62\r\n\r\nXXXX.instance.script_tag_connection().data_received(\"ping\");">>},
>
>              {state,undefined,
>                  {tcp_session,
>                      {{"localhost",8081},<0.98.0>},
>                      false,http,#Port<0.3069>,1,keep_alive},
>                  undefined,undefined,undefined,undefined,
>                  {[],[]},
>                  {[],[]},
>                  keep_alive,[],nolimit,nolimit,
>                  {options,
>                      {undefined,[]},
>                      0,2,5,120000,2,disabled,enabled,false},
>                  {timers,[],#Ref<0.0.0.227>},
>                  'httpc_manager_<0.83.0>',undefined}]},
>         {gen_server,handle_msg,5},
>         {proc_lib,init_p_do_apply,3}]}
>
> ---
> Mac hacker with a performance bent
> http://www.linkedin.com/in/joelreymont
>
>
> ________________________________________________________________
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org
>


-- 
Oscar Hellström, oscar@REDACTED
Office: +44 20 7655 0337
Mobile: +44 798 45 44 773
Erlang Training and Consulting Ltd
http://www.erlang-consulting.com/



More information about the erlang-questions mailing list