You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@mina.apache.org by Nitin <ni...@integramicro.com> on 2013/11/19 13:59:14 UTC

MINA: How to close the sessions with MINA

Dear All,

      We have developed one server using Apache MINA V2.0.4 where multiple
vendors connect and send the messages which needs to be processed and then
response have to be sent back to vendor. Currently we have put a strategy
that vendor has to send one message per connection and after getting
response or timeout vendor has to close the connection.

 

      But after sometime we realized that some of the vendors are not
closing connections and due that many sessions are remaining idle. To tackle
this we started using the sessionIdle(IoSession session, IdleStatus status)
event for each vendor connection and we use to close the session in this
event with session.close(true); 

 

But then I saw this link where it was saying that session.close(true) may
cause issue http://comments.gmane.org/gmane.comp.apache.mina.user/4616 

so we changed it to session.close(false); 

 

Now we are facing issue of Broken pipes. Suddenly we start getting below
ERROR and it will keep coming continuously and fills the log files only with
this error.

 

java.io.IOException: Broken pipe

      at sun.nio.ch.FileDispatcher.write0(Native Method)

      at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:29)

      at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:69)

      at sun.nio.ch.IOUtil.write(IOUtil.java:40)

      at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:334)

      at
org.apache.mina.transport.socket.nio.NioProcessor.write(NioProcessor.java:28
7)

      at
org.apache.mina.transport.socket.nio.NioProcessor.write(NioProcessor.java:44
)

      at
org.apache.mina.core.polling.AbstractPollingIoProcessor.writeBuffer(Abstract
PollingIoProcessor.java:950)

      at
org.apache.mina.core.polling.AbstractPollingIoProcessor.flushNow(AbstractPol
lingIoProcessor.java:874)

      at
org.apache.mina.core.polling.AbstractPollingIoProcessor.flush(AbstractPollin
gIoProcessor.java:799)

      at
org.apache.mina.core.polling.AbstractPollingIoProcessor.access$700(AbstractP
ollingIoProcessor.java:68)

      at
org.apache.mina.core.polling.AbstractPollingIoProcessor$Processor.run(Abstra
ctPollingIoProcessor.java:1146)

      at
org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:
64)

      at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.ja
va:886)

      at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:9
08)

      at java.lang.Thread.run(Thread.java:662)

We have observed that once above issue comes we end up in restarting our
MINA based server or sometimes the OS to bring it back to working state.

I would like to know in details how I can identify the idle session and with
our strategy of one message per connection how we can identify the idle
sessions and close them peacefully. 

 

Thanks in advance. Looking for concrete solution.

 

Thanks And Regards,

Nitin Phuria


Re: MINA: How to close the sessions with MINA

Posted by Emmanuel Lécharny <el...@gmail.com>.
Le 11/19/13 2:32 PM, Nitin a écrit :
> Thanks a ton for lightning fast reply and concrete suggestions on the
> problem shared. You mentioned that we should start using MINA V2.0.7 as many
> bugs are been fixed from V2.0.4 I presume I can simply replace the MINA Core
> Jar from V2.0.4 to V2.0.7, pls confirm.
Yes. But be sure to update the version number in your pom.xml (if you
are using maven).

If you have any pb with the switch, please post a mail here, we can most
certainly help you.

-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com 


RE: MINA: How to close the sessions with MINA

Posted by Emre Baykal <em...@mobiliz.com.tr>.
Nitin, 

You also need to switch your related classes to 2.0.7 type. There are some additional changes on class implementations as well.
Take a look at this link before working on replacing jar. (Although it covers changes between 2.x and 1.x, that might still be helping)
https://cwiki.apache.org/confluence/display/MINA/Changes+Between+2.x+and+1.x

Best,
Emre

-----Original Message-----
From: Nitin [mailto:nitinp@integramicro.com] 
Sent: Tuesday, November 19, 2013 3:32 PM
To: users@mina.apache.org
Subject: RE: MINA: How to close the sessions with MINA

Thanks a ton for lightning fast reply and concrete suggestions on the problem shared. You mentioned that we should start using MINA V2.0.7 as many bugs are been fixed from V2.0.4 I presume I can simply replace the MINA Core Jar from V2.0.4 to V2.0.7, pls confirm.

Thanks And Regards,
Nitin Phuria

-----Original Message-----
From: Emmanuel Lécharny [mailto:elecharny@gmail.com]
Sent: Tuesday, November 19, 2013 6:54 PM
To: users@mina.apache.org
Subject: Re: MINA: How to close the sessions with MINA

Le 11/19/13 1:59 PM, Nitin a écrit :
> Dear All,
>
>       We have developed one server using Apache MINA V2.0.4 where 
> multiple vendors connect and send the messages which needs to be 
> processed and then response have to be sent back to vendor. Currently 
> we have put a strategy that vendor has to send one message per 
> connection and after getting response or timeout vendor has to close the connection.

So far, so good.
>
>  
>
>       But after sometime we realized that some of the vendors are not 
> closing connections and due that many sessions are remaining idle. To
tackle
> this we started using the sessionIdle(IoSession session, IdleStatus
status)
> event for each vendor connection and we use to close the session in 
> this event with session.close(true);

That's the right way to do it.

>
>  
>
> But then I saw this link where it was saying that session.close(true) 
> may cause issue 
> http://comments.gmane.org/gmane.comp.apache.mina.user/4616

No.
>
> so we changed it to session.close(false);

Wrong. It will wait for all the pending messages to be sent to the
(vanished) client. That means forever.
>
>  
>
> Now we are facing issue of Broken pipes. Suddenly we start getting 
> below ERROR and it will keep coming continuously and fills the log 
> files only
with
> this error.
>
>  
>
> java.io.IOException: Broken pipe
>
>       at sun.nio.ch.FileDispatcher.write0(Native Method)

It's plain normal : the server is trying to send messages to a now disconnected server. And it will try again and again.
>
>
> We have observed that once above issue comes we end up in restarting 
> our MINA based server or sometimes the OS to bring it back to working state.
Yes.

>
> I would like to know in details how I can identify the idle session 
> and
with
> our strategy of one message per connection how we can identify the 
> idle sessions and close them peacefully.

Again, just do what you suggested : manage the sessionIdle() event and do close(true) (ie, clise with imediate effect, discarding the pending messages).


>
>  
>
> Thanks in advance. Looking for concrete solution.
close(true) and sessionIdle managed is a concrete solution to your problem. Don't read threads and deduce that there is a problem. If you have an issue with close(true) and idle management, then please post on this mailing list so that we can help you with valid solutions.


Ah, btw, I urge you to switch to 2.0.7. 2.0.4 is more than 2 years old, and many bugs have been fixed since.

Thnks for using MINA !


--
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com 


RE: MINA: How to close the sessions with MINA

Posted by Nitin <ni...@integramicro.com>.
Thanks a ton for lightning fast reply and concrete suggestions on the
problem shared. You mentioned that we should start using MINA V2.0.7 as many
bugs are been fixed from V2.0.4 I presume I can simply replace the MINA Core
Jar from V2.0.4 to V2.0.7, pls confirm.

Thanks And Regards,
Nitin Phuria

-----Original Message-----
From: Emmanuel Lécharny [mailto:elecharny@gmail.com] 
Sent: Tuesday, November 19, 2013 6:54 PM
To: users@mina.apache.org
Subject: Re: MINA: How to close the sessions with MINA

Le 11/19/13 1:59 PM, Nitin a écrit :
> Dear All,
>
>       We have developed one server using Apache MINA V2.0.4 where multiple
> vendors connect and send the messages which needs to be processed and then
> response have to be sent back to vendor. Currently we have put a strategy
> that vendor has to send one message per connection and after getting
> response or timeout vendor has to close the connection.

So far, so good.
>
>  
>
>       But after sometime we realized that some of the vendors are not
> closing connections and due that many sessions are remaining idle. To
tackle
> this we started using the sessionIdle(IoSession session, IdleStatus
status)
> event for each vendor connection and we use to close the session in this
> event with session.close(true); 

That's the right way to do it.

>
>  
>
> But then I saw this link where it was saying that session.close(true) may
> cause issue http://comments.gmane.org/gmane.comp.apache.mina.user/4616 

No.
>
> so we changed it to session.close(false); 

Wrong. It will wait for all the pending messages to be sent to the
(vanished) client. That means forever.
>
>  
>
> Now we are facing issue of Broken pipes. Suddenly we start getting below
> ERROR and it will keep coming continuously and fills the log files only
with
> this error.
>
>  
>
> java.io.IOException: Broken pipe
>
>       at sun.nio.ch.FileDispatcher.write0(Native Method)

It's plain normal : the server is trying to send messages to a now
disconnected server. And it will try again and again.
>
>
> We have observed that once above issue comes we end up in restarting our
> MINA based server or sometimes the OS to bring it back to working state.
Yes.

>
> I would like to know in details how I can identify the idle session and
with
> our strategy of one message per connection how we can identify the idle
> sessions and close them peacefully. 

Again, just do what you suggested : manage the sessionIdle() event and
do close(true) (ie, clise with imediate effect, discarding the pending
messages).


>
>  
>
> Thanks in advance. Looking for concrete solution.
close(true) and sessionIdle managed is a concrete solution to your
problem. Don't read threads and deduce that there is a problem. If you
have an issue with close(true) and idle management, then please post on
this mailing list so that we can help you with valid solutions.


Ah, btw, I urge you to switch to 2.0.7. 2.0.4 is more than 2 years old,
and many bugs have been fixed since.

Thnks for using MINA !


-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com 


Re: MINA: How to close the sessions with MINA

Posted by Emmanuel Lécharny <el...@gmail.com>.
Le 11/19/13 1:59 PM, Nitin a écrit :
> Dear All,
>
>       We have developed one server using Apache MINA V2.0.4 where multiple
> vendors connect and send the messages which needs to be processed and then
> response have to be sent back to vendor. Currently we have put a strategy
> that vendor has to send one message per connection and after getting
> response or timeout vendor has to close the connection.

So far, so good.
>
>  
>
>       But after sometime we realized that some of the vendors are not
> closing connections and due that many sessions are remaining idle. To tackle
> this we started using the sessionIdle(IoSession session, IdleStatus status)
> event for each vendor connection and we use to close the session in this
> event with session.close(true); 

That's the right way to do it.

>
>  
>
> But then I saw this link where it was saying that session.close(true) may
> cause issue http://comments.gmane.org/gmane.comp.apache.mina.user/4616 

No.
>
> so we changed it to session.close(false); 

Wrong. It will wait for all the pending messages to be sent to the
(vanished) client. That means forever.
>
>  
>
> Now we are facing issue of Broken pipes. Suddenly we start getting below
> ERROR and it will keep coming continuously and fills the log files only with
> this error.
>
>  
>
> java.io.IOException: Broken pipe
>
>       at sun.nio.ch.FileDispatcher.write0(Native Method)

It's plain normal : the server is trying to send messages to a now
disconnected server. And it will try again and again.
>
>
> We have observed that once above issue comes we end up in restarting our
> MINA based server or sometimes the OS to bring it back to working state.
Yes.

>
> I would like to know in details how I can identify the idle session and with
> our strategy of one message per connection how we can identify the idle
> sessions and close them peacefully. 

Again, just do what you suggested : manage the sessionIdle() event and
do close(true) (ie, clise with imediate effect, discarding the pending
messages).


>
>  
>
> Thanks in advance. Looking for concrete solution.
close(true) and sessionIdle managed is a concrete solution to your
problem. Don't read threads and deduce that there is a problem. If you
have an issue with close(true) and idle management, then please post on
this mailing list so that we can help you with valid solutions.


Ah, btw, I urge you to switch to 2.0.7. 2.0.4 is more than 2 years old,
and many bugs have been fixed since.

Thnks for using MINA !


-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com