Buggy code:
public class CloseChannels { @ Test @ Ignore public void testChannelClose ( ) throws Exception { final ExecutorService executor = Executors . newCachedThreadPool ( ) ; final ChannelServer . Configuration serverConfig = new ChannelServer . Configuration ( ) ; serverConfig . setBindAddress ( new InetSocketAddress ( InetAddress . getByName ( "127.0.0.1" ) , 6999 ) ) ; serverConfig . setEndpointName ( "Test" ) ; serverConfig . setUriScheme ( "testing" ) ; serverConfig . setExecutor ( executor ) ; ChannelServer server = ChannelServer . create ( serverConfig ) ; server . addChannelOpenListener ( "channel" , new OpenListener ( ) { @ Override public void registrationTerminated ( ) { } @ Override public void channelOpened ( Channel channel ) { System . out . println ( "Opened<seq2seq4repair_space>channel" ) ; final AbstractMessageHandler < Integer , Void > handler = new AbstractMessageHandler < Integer , Void > ( executor ) { @ Override protected ManagementRequestHandler < Integer , Void > getRequestHandler ( byte operationType ) { return new ManagementRequestHandler < Integer , Void > ( ) { @ Override public void handleRequest ( DataInput input , ActiveOperation . ResultHandler < Integer > resultHandler , ManagementRequestContext < Void > context ) throws IOException { System . out . println ( "Reading<seq2seq4repair_space>request" ) ; ProtocolUtils . expectHeader ( input , 11 ) ; final int i = input . readInt ( ) ; context . executeAsync ( new ManagementRequestContext . AsyncTask < Void > ( ) { @ Override public void execute ( ManagementRequestContext < Void > context ) throws Exception { ProtocolUtils . writeResponse ( new ProtocolUtils . ResponseWriter ( ) { @ Override public void write ( final FlushableDataOutput output ) throws IOException { System . out . println ( ( "Writing<seq2seq4repair_space>response<seq2seq4repair_space>" + i ) ) ; output . write ( 22 ) ; output . writeInt ( i ) ; } } , context ) ; } } ) ; } } ; } } ; channel . addCloseHandler ( new org . jboss . remoting3 . CloseHandler < Channel > ( ) { public void handleClose ( final Channel closed , final IOException exception ) { System . out . println ( "server<seq2seq4repair_space>close<seq2seq4repair_space>handler!!!" ) ; } } ) ; } } ) ; try { for ( int i = 0 ; i < 1000 ; i ++ ) { ProtocolChannelClient . Configuration clientConfig = new ProtocolChannelClient . Configuration ( ) ; clientConfig . setEndpointName ( "Test" ) ; clientConfig . setUri ( new URI ( "testing:////127.0.0.1:6999" ) ) ; clientConfig . setUriScheme ( "testing" ) ; ProtocolChannelClient protocolClient = ProtocolChannelClient . create ( clientConfig ) ; final int val = i ; <START_BUG> final Connection connection = protocolClient . connect ( null ) . get ( ) ; <END_BUG> System . out . println ( "Opening<seq2seq4repair_space>channel" ) ; final Channel clientChannel = connection . openChannel ( "channel" , EMPTY ) . get ( ) ; clientChannel . addCloseHandler ( new org . jboss . remoting3 . CloseHandler < Channel > ( ) { public void handleClose ( final Channel closed , final IOException exception ) { System . out . println ( "client<seq2seq4repair_space>close<seq2seq4repair_space>handler" ) ; } } ) ; final SimpleHandlers . SimpleClient client = SimpleClient . create ( clientChannel , executor ) ; try { final ManagementRequest < Integer , Void > request = new AbstractManagementRequest < Integer , Void > ( ) { @ Override public byte getOperationType ( ) { return 66 ; } @ Override protected void sendRequest ( ActiveOperation . ResultHandler < Integer > resultHandler , ManagementRequestContext < Void > context , FlushableDataOutput output ) throws IOException { System . out . println ( "Writing<seq2seq4repair_space>request" ) ; output . write ( 11 ) ; output . writeInt ( val ) ; } @ Override public void handleRequest ( DataInput input , ActiveOperation . ResultHandler < Integer > resultHandler , ManagementRequestContext < Void > voidManagementRequestContext ) throws IOException { System . out . println ( "Reading<seq2seq4repair_space>response" ) ; ProtocolUtils . expectHeader ( input , 22 ) ; resultHandler . done ( input . readInt ( ) ) ; } } ; int result = client . executeForResult ( request ) ; Assert . assertEquals ( val , result ) ; } finally { IoUtils . safeClose ( protocolClient ) ; } } } finally { server . close ( ) ; executor . shutdown ( ) ; executor . awaitTermination ( 10 , TimeUnit . SECONDS ) ; executor . shutdownNow ( ) ; } } }

Fix:
final Connection connection = protocolClient . connectSync ( null ) ;