Hi,
Thank you for sharing your thoughts regarding this issue. I am using Mina
to develop a TCP client-server program. I experienced a similar issue while
I was trying to perform the following operation:
I would like to shutdown the NioSocketAcceptor instance when it receives a
special message from a client (admin client). Upon receiving the message I
would like the program to notify all the active IoSessions about the server
shutdown by broadcasting a SHUTDOWN message and then dispose the
NioSocketAcceptor instance. I would like to dispose the acceptor instance
only after the message has been sent successfully.
messageReceived(){
- write SHUTDOWN message to all managed ioSessions , wait for the write
operation to complete.
- close the ioSessions and wait for the close operation to complete.
- unbind and dispose the acceptor.
}
What would be the recommended approach to perform this type of a task?
How can I prevent the IO processor thread from DEAD LOCK? Could you also
explain about the threading model that is recommended in this case? Can
ExecutorFilter be used to solve this type of problem?
What role can IOFutureListener perform in this type of task?
Thanks,
Richards.
On Tue, Jul 16, 2013 at 7:42 AM, Jose María Zaragoza <[email protected]>
wrote:
> Thanks.
> I was executing some logic in callback methods, who are executed in a
> separated IoProcessor thread.
> As logic was executed in a thread to process asynchronous callbacks, when
> logic tried to close session, an exception was thrown
>
> I'll try don't execute logic code in callbacks methods
>
>
>
>
> 2013/7/16 Emmanuel Lécharny <[email protected]>
>
> > Le 7/16/13 11:29 AM, Jose María Zaragoza a écrit :
> > > Hello:
> > >
> > > I'm using Mina 2.0.7 and I'm getting this error where close a session
> > >
> > >
> > > java.lang.IllegalStateException: DEAD LOCK: IoFuture.await() was
> invoked
> > > from an I/O processor thread. Please use IoFutureListener or
> configure a
> > > proper thread model alternatively.
> > >
> > > at
> > >
> > org.apache.mina.core.future.DefaultIoFuture.checkDeadLock(
> DefaultIoFuture.java:240)
> > >
> > > at
> > >
> > org.apache.mina.core.future.DefaultIoFuture.await0(
> DefaultIoFuture.java:210)
> > >
> > > at
> > >
> > org.apache.mina.core.future.DefaultIoFuture.awaitUninterruptibly(
> DefaultIoFuture.java:153)
> > >
> > >
> > > I'm closing session with the next code:
> > >
> > > if (this.session != null)
> > > {
> > >
> > > CloseFuture future = this.session.close(false);
> > > future.await(10000);
> > > if (!future.isClosed())
> > > throw new Exception("Disconnect timeout after waiting 10 seconds");
> > > }
> > >
> > > What could be the right solution?
> >
> > You can't close the session and wait for the future to be completed, as
> > the future will be updated by the thread you are on.
> >
> > Let me explain what's going on :
> > - you are on a thread that handle the session. You require this session
> > to be closed.
> > - the current thread will update a set with the session to be closed
> > - the main server thread will process this set when it will be able to
> > do it (ie, probably in the next few ms after you closed the session)
> > - it's very likely that the main server thread will reuse the same
> > thread than the one you hold for the session (unless you specifically
> > tell the server to manage threads differently, it will *always* use the
> > same thread for a given session. If you have, say, three IoProcessor,
> > you will have three threads created, and all the sessions will be evenly
> > spreaded on those three threads, but each session will always use the
> > same thread)
> > - and as you hold the thread waiting for the future to be completed,
> > this thread can't be used to update the future status by the main server
> > thread...
> >
> > what exactly are you trying to do with the check on the session timeout
> > ? You can most certainly use the idle event to manage the timeout...
> >
> >
> > --
> > Regards,
> > Cordialement,
> > Emmanuel Lécharny
> > www.iktek.com
> >
> >
>