Hi list,

MdcInjectionFilter fails on nested call. It assume only one IoSession on
a thread at any time.

See attached source for a test case.  You need both port 21 and 22 open
on localhost to run the test case. If you can't open the attachment, try
  http://www.sdiz.net/temp/MainTest.java

(btw, checkDeadlock() in await() think I have a deadlock when I remove
the Thread.sleep() call on line 39 ... is this bug?)


-- 
This space was intended to be left blank.




import java.net.InetSocketAddress;

import org.apache.mina.common.*;
import org.apache.mina.filter.logging.LoggingFilter;
import org.apache.mina.filter.logging.MdcInjectionFilter;
import org.apache.mina.transport.socket.SocketConnector;
import org.apache.mina.transport.socket.nio.NioSocketConnector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MainTest {
	private static final int TEST_PORT1 = 21;
	private static final int TEST_PORT2 = 22;
	
	public static void main(final String[] args) throws InterruptedException {
		final NioSocketConnector conn1 = new NioSocketConnector(1);
		final DefaultIoFilterChainBuilder f1 = conn1.getFilterChain();
		f1.addLast("mdc", new MdcInjectionFilter());
		f1.addLast("log", new LoggingFilter());
		conn1.setHandler(new IoHandlerAdapter());
		
		final SocketConnector conn2 = new NioSocketConnector(1);
		final DefaultIoFilterChainBuilder f2 = conn2.getFilterChain();
		f2.addLast("mdc", new MdcInjectionFilter());
		f2.addLast("log", new LoggingFilter());
		
		conn2.setHandler(new IoHandlerAdapter() {
			Logger logger = LoggerFactory.getLogger(this.getClass());
			
			@Override
			public void sessionOpened(final IoSession session) throws Exception {
				logger.info("[conn2] before connect to conn1");
				
				final ConnectFuture cf = conn1.connect(new InetSocketAddress("localhost", TEST_PORT2));
				logger.info("[conn2] after connect to conn1");
				
				Thread.sleep(3000); // WAIT FOR CONNECT
				cf.await(); // (or await will think this as deadlock)
				
				cf.getSession().write(IoBuffer.wrap("HELP\n".getBytes("LATIN1")));
				// BUG HERE!!! we have no MDC here!! vv
				logger.info("[conn2] after write to conn1");
			}
		});
		
		conn2.connect(new InetSocketAddress("localhost", TEST_PORT1));
		
		Thread.sleep(60000);
	}
}

Reply via email to