Apache Mina  1.1.7
Java 1.6.0-13
Windows 7

XP에서 윈도우 7으로 전환했는데. mina를 테스트하다가 이상한 것이 생겼다.
I changed my windows into Windows 7 from Windows XP.

재현 시나리오는 이유없이 그냥 "Invalid argument" Exception이 나오는 것이 아닌가? 될 때도 있고 안 될 때도 있고.. 그랬다.



Exception in thread "Thread-4" org.apache.mina.common.RuntimeIOException: java.net.SocketException: Invalid argument: sun.nio.ch.Net.setIntOption
at org.apache.mina.transport.socket.nio.SocketSessionImpl$SessionConfigImpl.setKeepAlive(SocketSessionImpl.java:252)
at org.apache.mina.transport.socket.nio.SocketSessionImpl.<init>(SocketSessionImpl.java:94)
at org.apache.mina.transport.socket.nio.SocketConnector.newSession(SocketConnector.java:350)
at org.apache.mina.transport.socket.nio.SocketConnector.processSessions(SocketConnector.java:290)
at org.apache.mina.transport.socket.nio.SocketConnector.access$900(SocketConnector.java:53)
at org.apache.mina.transport.socket.nio.SocketConnector$Worker.run(SocketConnector.java:395)
at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:43)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.net.SocketException: Invalid argument: sun.nio.ch.Net.setIntOption
at sun.nio.ch.Net.setIntOption0(Native Method)
at sun.nio.ch.Net.setIntOption(Net.java:152)
at sun.nio.ch.SocketChannelImpl$1.setInt(SocketChannelImpl.java:372)
at sun.nio.ch.SocketOptsImpl.setBoolean(SocketOptsImpl.java:38)
at sun.nio.ch.SocketOptsImpl.keepAlive(SocketOptsImpl.java:92)
at sun.nio.ch.OptionAdaptor.setKeepAlive(OptionAdaptor.java:139)
at sun.nio.ch.SocketAdaptor.setKeepAlive(SocketAdaptor.java:322)
at org.apache.mina.transport.socket.nio.SocketSessionImpl$SessionConfigImpl.setKeepAlive(SocketSessionImpl.java:248)
... 7 more



확인을 해보니. 이미 아파치 jira에 있던 내용이었다.
I checked in google, that issue was in apache jira.

https://issues.apache.org/jira/browse/DIRMINA-379


Solution  :


 내가 사용했던 코드는 다음과 같다.
I trited to use static class member when I used SocketConnector in Mina.
public class ImageUploaderConnector {
...
 private static SocketConnector socketConnector;
 private static SocketConnectorConfig config;
 private static DefaultIoFilterChainBuilder filterChainBuilder = new DefaultIoFilterChainBuilder();
 private static  final SocketHandler HANDLER = new SocketHandler();

=>

원인은 아마도 static 메소드안에서 초기화와 set을 하면서 동기화 문제가 생긴 것 같다.
I think the exception was confliction between initialization and set method calling.

Exception 나는 것을 확인하기 위해서 static을 지워보니. 더이상 에러가 나지 않는다!!
I deleted static, no longer exception thrown!!
Every create a new SocketConnector instance for every request, the exception never is thrown..


public class ImageUploaderConnector {
...
 private SocketConnector socketConnector;
 private SocketConnectorConfig config;
 private DefaultIoFilterChainBuilder filterChainBuilder = new DefaultIoFilterChainBuilder();
 private final SocketHandler HANDLER = new SocketHandler();



At below, someone says..

 see this as well (Windows 2000, 2003 Server and Vista), but only when reusing one SocketConnector for many client sessions, connecting clients very quickly in sequence.

If I create a new SocketConnector instance for every client connection, the problem goes away. If this is due to the overhead of creating a new SocketConnector for each client, I do not know. I imagined one SocketConnector was multi-thread safe for creating many client connections in parallell (ref. the connectQueue etc ..) ?

(http://old.nabble.com/-jira--Created:-(DIRMINA-379)-setKeepAlive-setTcpNoDelay-and-exceptions-in-Windows-Vista-td10689620i20.html)

Posted by 김용환 '김용환'

댓글을 달아 주세요