hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hiranya Jayathilaka <hiranya...@gmail.com>
Subject Re: Migrating Synapse to Latest HTTP Core
Date Thu, 25 Jul 2013 01:40:47 GMT

On Jul 24, 2013, at 5:49 AM, Oleg Kalnichevski <olegk@apache.org> wrote:

> On Wed, 2013-07-24 at 13:45 +0200, Oleg Kalnichevski wrote:
>> On Wed, 2013-07-24 at 01:40 -0700, Hiranya Jayathilaka wrote:
>>> Hi again,
>>> 
>>> On Jul 24, 2013, at 1:36 AM, Hiranya Jayathilaka
>>> <hiranya911@gmail.com> wrote:
> 
> ...
> 
>>> 
>>> I've also noticed that the problem doesn't occur if we do not send any
>>> messages in the 1st round. I verified this behavior with Synapse too.
>>> If a test case doesn't send any messages to Synapse, the test case
>>> that follows will run without any issues.
>>> 
>> 
>> Hiranya
>> 
>> (1) The socket is CLOSE_WAIT state is from the client connection. It has
>> nothing to do with the problem and can be gotten rid of by shutting down
>> the client connection pool. 
>> 
>> client.getConnectionManager().shutdown();
>> 
>> (2) The 'Address already in use' problem goes away if the server is
>> configured to re-use socket address
>> 
>> reactorConfig.setSoReuseAddress(true);
>> 
>> I think this option should be activated for integration tests running
>> inside the same JVM anyway, but I'll investigate why the address remains
>> bound even after the listener has been shut down. I am not yet sure
>> whether this is a bug or an expected behavior.
>> 
>> Oleg 
>> 
>> 
> 
> Just a quick follow-up. The problem appears to be Linux specific. The
> same test app works fine for me on Windows XP.
> 
> I also modified slightly your code in order to have a finer control over
> the client side.
> ---
> System.out.println("Round 1");
> initServer();
> 
> DefaultHttpClientConnection conn = new DefaultHttpClientConnection();
> try {
>    Socket socket = new Socket("localhost", 8280);
>    conn.bind(socket, new BasicHttpParams());
>    conn.setSocketTimeout(1000);
>    conn.sendRequestHeader(new BasicHttpRequest("GET", "/"));
>    conn.flush();
>    conn.receiveResponseHeader();
> } catch (SocketTimeoutException ex) {
> } finally {
>    conn.close(); 
>   // this closes the socket the connection is bound to
> }
> 
> System.out.println("Waiting - Shutdown in 5 secs");
> Thread.sleep(5000);
> shutdown();
> 
> System.out.println("\n\nRound 2");
> initServer();
> System.out.println("Waiting - Shutdown in 5 secs");
> Thread.sleep(5000);
> shutdown();
> ---
> 
> If you just comment out the conn#receiveResponseHeader() statement the
> client side socket will never be put into read mode, and (surprise,
> surprise) the listener address will no longer be stuck in the bound
> state.
> 
> I am neither a Linux nor a TCP/IP specialist. I cannot tell why this is
> happening. However, by the look of it, one must use 'SO_REUSE_ADDRESS'
> option on Linux in order to be able to shut down and re-open the
> listener on the same address if the socket bound to that address had
> some data passing through it.
> 
> Anyone happens to have an idea?

I came across [1] which describes the semantics of SO_REUSEADDR in great detail. And yes,
the behavior is very much OS dependent (the article explains why our test case works in Windows
without any issues). 

Thanks,
Hiranya

[1] - http://stackoverflow.com/questions/14388706/socket-options-so-reuseaddr-and-so-reuseport-how-do-they-differ-do-they-mean-t

> 
> Oleg
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
> For additional commands, e-mail: dev-help@synapse.apache.org
> 

--
Hiranya Jayathilaka
Mayhem Lab/RACE Lab;
Dept. of Computer Science, UCSB;  http://cs.ucsb.edu
E-mail: hiranya@cs.ucsb.edu;  Mobile: +1 (805) 895-7443
Blog: http://techfeast-hiranya.blogspot.com


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message