title: Why does Netty client connection future.operationComplete get called within the caller thread?
body: <p>Below I have demonstrated how I connect using Netty <code>NioClientSocketChannelFactory</code>.  Connect returns a future and I can check if 
  the connection is successful/failed.  </p>
  
  <p><strong>My understanding is that the connection process is non-locking and so the operationComplete method will be called by netty thread (not within the caller thread) And so the caller thread will exit.</strong></p>
  
  <p>Most of the time it works this way, on various windows deployments I have.  </p>
  
  <p>But on one of the deployments I noticed that when connection fails, the <code>operationComplete</code> method is invoked in my caller thread instead of netty thread.
  The exception thrown in also caught in the caller thread.  I did not expect this.</p>
  
  <p>In my code, when connection fails, I reattempt a connection (not demonstrated below)...and since it happens in my caller thread, I never return from my connect call, since
  the <code>operationComplete</code> is called in my caller thread.</p>
  
  <p>What am I doing wrong?  NOTE-I dont have the <code>future.awaitUninterruptibly</code> call anywhwere.</p>
  
  <pre><code>public static void main(String[] args)
  {
          String host = "localhost";
          int port = 5555;
          ChannelFactory factory = new NioClientSocketChannelFactory(Executors
                          .newCachedThreadPool(), Executors.newCachedThreadPool());
          MyHandler handler = new MyHandler();
          PipelineFactory factory = new PipelineFactory(handler);
          ClientBootstrap bootstrap = new ClientBootstrap(factory);
          ChannelFuture future = bootstrap.connect(new InetSocketAddress(host, port));
  
          future.addListener(new ChannelFutureListener()
          {
                  @Override
                  public void operationComplete(ChannelFuture future) throws Exception
                  {
                      if (future.isSuccess()) {
                          // SUCCESS
                      }
                      else
                      {
                          // FAILURE
                      }
                  }
          });
  }
  </code></pre>