Buggy code:
public class CloseChannels { @ Test public void testChannelClose ( ) throws Exception { ExecutorService executor = Executors . newCachedThreadPool ( ) ; 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 ManagementChannel protocolChannel = new ManagementChannelFactory ( new ManagementOperationHandler ( ) { @ Override public ManagementRequestHandler getRequestHandler ( byte id ) { return new ManagementRequestHandler ( ) { int i ; @ Override protected void readRequest ( DataInput input ) throws IOException { System . out . println ( "Reading<seq2seq4repair_space>request" ) ; ProtocolUtils . expectHeader ( input , 11 ) ; i = input . readInt ( ) ; } @ Override protected void writeResponse ( FlushableDataOutput output ) throws IOException { System . out . println ( ( "Writing<seq2seq4repair_space>response<seq2seq4repair_space>" + ( i ) ) ) ; output . write ( 22 ) ; output . writeInt ( i ) ; } } ; } } ) . create ( "channel" , channel ) ; protocolChannel . startReceiving ( ) ; channel . addCloseHandler ( new org . jboss . remoting3 . CloseHandler < Channel > ( ) { @ Override public void handleClose ( Channel closed ) { System . out . println ( "server<seq2seq4repair_space>close<seq2seq4repair_space>handler!!!" ) ; } } ) ; } } ) ; try { for ( int i = 0 ; i < 1000 ; i ++ ) { ProtocolChannelClient . Configuration < ManagementChannel > clientConfig = new ProtocolChannelClient . Configuration < ManagementChannel > ( ) ; clientConfig . setEndpointName ( "Test" ) ; clientConfig . setExecutor ( executor ) ; clientConfig . setUri ( new URI ( "testing:////127.0.0.1:6999" ) ) ; clientConfig . setUriScheme ( "testing" ) ; clientConfig . setChannelFactory ( new ManagementChannelFactory ( ) ) ; ProtocolChannelClient < ManagementChannel > client = ProtocolChannelClient . create ( clientConfig ) ; final int val = i ; <START_BUG> client . connect ( ) ; <END_BUG> System . out . println ( "Opening<seq2seq4repair_space>channel" ) ; final ManagementChannel clientChannel = client . openChannel ( "channel" ) ; clientChannel . addCloseHandler ( new org . jboss . remoting3 . CloseHandler < Channel > ( ) { @ Override public void handleClose ( Channel closed ) { System . out . println ( "client<seq2seq4repair_space>close<seq2seq4repair_space>handler" ) ; } } ) ; clientChannel . startReceiving ( ) ; try { int result = new ManagementRequest < Integer > ( ) { @ Override protected byte getRequestCode ( ) { return 66 ; } @ Override protected void writeRequest ( int protocolVersion , FlushableDataOutput output ) throws IOException { System . out . println ( "Writing<seq2seq4repair_space>request" ) ; output . write ( 11 ) ; output . writeInt ( val ) ; } protected Integer readResponse ( DataInput input ) throws IOException { System . out . println ( "Reading<seq2seq4repair_space>response" ) ; ProtocolUtils . expectHeader ( input , 22 ) ; return input . readInt ( ) ; } } . executeForResult ( executor , ManagementClientChannelStrategy . create ( clientChannel ) ) ; Assert . assertEquals ( val , result ) ; } finally { IoUtils . safeClose ( client ) ; } } } finally { server . close ( ) ; executor . shutdown ( ) ; executor . awaitTermination ( 10 , TimeUnit . SECONDS ) ; executor . shutdownNow ( ) ; } } }

Fix:
client . connect ( null ) ;