开发者

Dead sessions in apache mina

We have a apache mina based GPRS gateway(server). Sometimes, usually when the connection is terminated from client side brutally i.e, power cable unplugged or any other unusual shutdown or some problem with network, it is not removed or closed at server side. It remain there, in idle state, for I don,t know how long( may be forever). At times we face issues while shutting the server down, MINA take too much time and at times we have to kill it eventually. We suspect that this issue is related to dead connection problem.

Actually, this dead connection make sense. Since the connection is closed brutally and mina don't have a way to check it (that's how tcp session works). We as a workaround, devised a solution that we will close session if it remain idle (both read and write) for let say 30 min(or any configurable time). Whi开发者_C百科ch we do not like for 2 reasons:

1- It doesn't look nice.

2- Plus we have a rule that client make a persistent connection with the server. So, it's a bit difficult to set an 'idle timeout' as we can't just close any session which has been idle for x min/hrs as it can be a valid connection.

So, is there any nicer and more safer (in our case) way to detect and clean these dead connection in MINA?


In both cases long not active connection and lost connection - having no activity in channel should result in timeout after configured time in every layer of OSI model. E.g. you firewall/router/server may timeout inactive connection entry in 10 minutes, then you application layer connection should also do that after 10 minutes - waiting more makes no sense.

To prevent silent connections from timeout keep-alive protocol should be introduced. It may be ping (not exactly ICMP) or other form of periodic no-operation communication. When peer is alive it should respond and thus refresh timeout countdown on all network layers. After failed attempt caused by timeout or layer signaling broken connection you can assume that your application layer connection is also broken.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜