You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Daniel Cheng <gm...@sdiz.net> on 2008/02/18 16:54:37 UTC
MdcInjectionFilter with nested calls
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.
Re: MdcInjectionFilter with nested calls
Posted by Daniel Cheng <gm...@sdiz.net>.
Hi,
Maarten Bosteels wrote:
> Hello Daniel,
>
> On Feb 18, 2008 4:54 PM, Daniel Cheng <gm...@sdiz.net> wrote:
>
>> Hi list,
>>
>> MdcInjectionFilter fails on nested call. It assume only one IoSession on
>> a thread at any time.
>
>
> yes, that might be an issue, not sure, I will investigate it.
> Which session info would you expect to be in the MDC, both ?
>
The latter MdcInjectionFilter should not remove all keys in MDC.
I think it should behave like a stack.
If you try my program, the "BUG HERE" line have no MDC at all.
>> 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?)
>
>
> I don't think so.
> Instead of using cf.await() you should use an IoFutureListener:
>
[....]
okay.
I wrote this case just to demonstrate the MDC bug...
I never do this in my applications.
But the exception from checkDeadlock() is misleading,
as this case have no deadlock at all.
> This also solves the MDC problem.
Sure. But this MDC problem is much more common.
Consider an application-level packet router..
It always have to send packets from one session to another..
>
> Maarten
>
Daniel Cheng
Re: MdcInjectionFilter with nested calls
Posted by Maarten Bosteels <mb...@gmail.com>.
Hello Daniel,
On Feb 18, 2008 4:54 PM, Daniel Cheng <gm...@sdiz.net> wrote:
> Hi list,
>
> MdcInjectionFilter fails on nested call. It assume only one IoSession on
> a thread at any time.
yes, that might be an issue, not sure, I will investigate it.
Which session info would you expect to be in the MDC, both ?
>
>
> 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?)
I don't think so.
Instead of using cf.await() you should use an IoFutureListener:
Your code:
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!!
logger.info("[conn2] after write to conn1");
}
Better:
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");
final byte[] bytes = "HELP\n".getBytes("LATIN1");
cf.addListener(new IoFutureListener<ConnectFuture>() {
public void operationComplete(ConnectFuture future) {
future.getSession().write(IoBuffer.wrap(bytes));
logger.info("[conn2] after write to conn1");
}
});
}
This also solves the MDC problem.
Maarten
> --
> This space was intended to be left blank.
>
>
>
>