You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Qi <sa...@gmail.com> on 2007/12/17 08:48:35 UTC

WriteFuture.join() hangs when called in IoHandler.sessionOpened() in Datagram transport.

Hi there,

I've just found a possible bug in MINA Datagram transport.

In my handler class, I was trying to write some messages once the
sessionOpened event is fired, while the program will hang if I get the
writeFuture and call join() on it.
If I call join with a timeout parameter, after the operation gets timeout,
WriteFuture.isWritten returns false.
(Same senario would go through if it's via SocketConnector transport, as
showing in the sumup example.)


However, if I don't place the write operation inside sessionOpened();
instead, I placed they after DatagramConnector.connect(), then writes will
successfully go though.

I'm using MINA 1.1.5 and JRE 1.6.

Source code that demostrate the problem is attached.
http://www.nabble.com/file/p14370126/BroadcastSender.java
BroadcastSender.java 
-- 
View this message in context: http://www.nabble.com/WriteFuture.join%28%29-hangs-when-called-in-IoHandler.sessionOpened%28%29-in-Datagram-transport.-tp14370126s16868p14370126.html
Sent from the Apache MINA Support Forum mailing list archive at Nabble.com.


Re: WriteFuture.join() hangs when called in IoHandler.sessionOpened() in Datagram transport.

Posted by Trustin Lee <tr...@gmail.com>.
On Dec 27, 2007 7:57 AM, Steve Johns <st...@gmail.com> wrote:
> Are you saying Mina API Interface WriteFuture example is NOT a proper one?

Well, it depends on situation.  It is sometimes more convenient to use
WriteFuture.join() and it will work as long as you have inserted an
ExecutorFilter in the filter chain.  I prefer using IoFutureListener
though.

HTH,
Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6

Re: WriteFuture.join() hangs when called in IoHandler.sessionOpened() in Datagram transport.

Posted by Steve Johns <st...@gmail.com>.
Are you saying Mina API Interface WriteFuture example is NOT a proper one?
Thanks.

On Dec 18, 2007 3:14 PM, Trustin Lee <tr...@gmail.com> wrote:

> Hi Qi,
>
> It's not a bug but a kind of dead lock caused by misuse of the API.
>
> You are usually not supposed to call IoFuture.join() within an
> IoHandler because the IoHandler methods might be being executed in the
> same thread with the I/O processor thread.  You wrote something and
> you call join() to wait for the I/O processor thread to finish the
> write operation in the I/O processor thread, then join() won't return
> at all.  MINA 2 detects this kind of situation automatically and emits
> advisory exception, but it's not in MINA 1.x unfortunately.
>
> The alternative to join() is adding an IoFutureListener.
>
> HTH,
> Trustin
>
> On Dec 17, 2007 4:48 PM, Qi <sa...@gmail.com> wrote:
> >
> > Hi there,
> >
> > I've just found a possible bug in MINA Datagram transport.
> >
> > In my handler class, I was trying to write some messages once the
> > sessionOpened event is fired, while the program will hang if I get the
> > writeFuture and call join() on it.
> > If I call join with a timeout parameter, after the operation gets
> timeout,
> > WriteFuture.isWritten returns false.
> > (Same senario would go through if it's via SocketConnector transport, as
> > showing in the sumup example.)
> >
> >
> > However, if I don't place the write operation inside sessionOpened();
> > instead, I placed they after DatagramConnector.connect(), then writes
> will
> > successfully go though.
> >
> > I'm using MINA 1.1.5 and JRE 1.6.
> >
> > Source code that demostrate the problem is attached.
> > http://www.nabble.com/file/p14370126/BroadcastSender.java
> > BroadcastSender.java
> > --
> > View this message in context:
> http://www.nabble.com/WriteFuture.join%28%29-hangs-when-called-in-IoHandler.sessionOpened%28%29-in-Datagram-transport.-tp14370126s16868p14370126.html
> > Sent from the Apache MINA Support Forum mailing list archive at
> Nabble.com <http://nabble.com/>.
> >
> >
>
>
>
> --
> what we call human nature is actually human habit
> --
> http://gleamynode.net/
> --
> PGP Key ID: 0x0255ECA6
>

Re: WriteFuture.join() hangs when called in IoHandler.sessionOpened() in Datagram transport.

Posted by Qi <sa...@gmail.com>.
Hi Trustin,

Thanks a lot, I have taken the IoFutureListener approach. 
Btw, It's a real flexible and good design to have all these listeners.

Cheers,
Qi


Trustin Lee wrote:
> 
> Hi Qi,
> 
> It's not a bug but a kind of dead lock caused by misuse of the API.
> 
> You are usually not supposed to call IoFuture.join() within an
> IoHandler because the IoHandler methods might be being executed in the
> same thread with the I/O processor thread.  You wrote something and
> you call join() to wait for the I/O processor thread to finish the
> write operation in the I/O processor thread, then join() won't return
> at all.  MINA 2 detects this kind of situation automatically and emits
> advisory exception, but it's not in MINA 1.x unfortunately.
> 
> The alternative to join() is adding an IoFutureListener.
> 
> HTH,
> Trustin
> 
> On Dec 17, 2007 4:48 PM, Qi <sa...@gmail.com> wrote:
>>
>> Hi there,
>>
>> I've just found a possible bug in MINA Datagram transport.
>>
>> In my handler class, I was trying to write some messages once the
>> sessionOpened event is fired, while the program will hang if I get the
>> writeFuture and call join() on it.
>> If I call join with a timeout parameter, after the operation gets
>> timeout,
>> WriteFuture.isWritten returns false.
>> (Same senario would go through if it's via SocketConnector transport, as
>> showing in the sumup example.)
>>
>>
>> However, if I don't place the write operation inside sessionOpened();
>> instead, I placed they after DatagramConnector.connect(), then writes
>> will
>> successfully go though.
>>
>> I'm using MINA 1.1.5 and JRE 1.6.
>>
>> Source code that demostrate the problem is attached.
>> http://www.nabble.com/file/p14370126/BroadcastSender.java
>> BroadcastSender.java
>> --
>> View this message in context:
>> http://www.nabble.com/WriteFuture.join%28%29-hangs-when-called-in-IoHandler.sessionOpened%28%29-in-Datagram-transport.-tp14370126s16868p14370126.html
>> Sent from the Apache MINA Support Forum mailing list archive at
>> Nabble.com.
>>
>>
> 
> 
> 
> -- 
> what we call human nature is actually human habit
> --
> http://gleamynode.net/
> --
> PGP Key ID: 0x0255ECA6
> 
> 

-- 
View this message in context: http://www.nabble.com/WriteFuture.join%28%29-hangs-when-called-in-IoHandler.sessionOpened%28%29-in-Datagram-transport.-tp14370126s16868p14430072.html
Sent from the Apache MINA Support Forum mailing list archive at Nabble.com.


Re: WriteFuture.join() hangs when called in IoHandler.sessionOpened() in Datagram transport.

Posted by Trustin Lee <tr...@gmail.com>.
Hi Qi,

It's not a bug but a kind of dead lock caused by misuse of the API.

You are usually not supposed to call IoFuture.join() within an
IoHandler because the IoHandler methods might be being executed in the
same thread with the I/O processor thread.  You wrote something and
you call join() to wait for the I/O processor thread to finish the
write operation in the I/O processor thread, then join() won't return
at all.  MINA 2 detects this kind of situation automatically and emits
advisory exception, but it's not in MINA 1.x unfortunately.

The alternative to join() is adding an IoFutureListener.

HTH,
Trustin

On Dec 17, 2007 4:48 PM, Qi <sa...@gmail.com> wrote:
>
> Hi there,
>
> I've just found a possible bug in MINA Datagram transport.
>
> In my handler class, I was trying to write some messages once the
> sessionOpened event is fired, while the program will hang if I get the
> writeFuture and call join() on it.
> If I call join with a timeout parameter, after the operation gets timeout,
> WriteFuture.isWritten returns false.
> (Same senario would go through if it's via SocketConnector transport, as
> showing in the sumup example.)
>
>
> However, if I don't place the write operation inside sessionOpened();
> instead, I placed they after DatagramConnector.connect(), then writes will
> successfully go though.
>
> I'm using MINA 1.1.5 and JRE 1.6.
>
> Source code that demostrate the problem is attached.
> http://www.nabble.com/file/p14370126/BroadcastSender.java
> BroadcastSender.java
> --
> View this message in context: http://www.nabble.com/WriteFuture.join%28%29-hangs-when-called-in-IoHandler.sessionOpened%28%29-in-Datagram-transport.-tp14370126s16868p14370126.html
> Sent from the Apache MINA Support Forum mailing list archive at Nabble.com.
>
>



-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6