0

I have a java1.6 gateway application runs on aix. During the day millions of messages passing through successfully but when I look at logs I see a few logs like stacktrace below. log1:

java.net.SocketException: Invalid argument
    at java.io.DataOutputStream.write(DataOutputStream.java:119)
    at org.apache.commons.io.IOUtils.copy(IOUtils.java:921)
    at org.mule.providers.http.HttpServerConnection.writeResponse(HttpServerConnection.java:223)
    at com.ibtech.smg.esb.providers.esb.ESBHttpMessageReceiver$NewHttpWorker.run(ESBHttpMessageReceiver.java:162)
    at org.mule.impl.work.WorkerContext.run(WorkerContext.java:290)

log2:

java.net.SocketException: Invalid argument
    at java.net.SocketOutputStream.socketWrite0(Native Method)
    at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:125)
    at java.net.SocketOutputStream.write(SocketOutputStream.java:171)
    at java.io.DataOutputStream.write(DataOutputStream.java:119)
    at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:234)
    at sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:304)
    at sun.nio.cs.StreamEncoder.implFlush(StreamEncoder.java:308)
    at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:154)
    at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:288)
    at java.io.BufferedWriter.flush(BufferedWriter.java:266)
    at java.io.FilterWriter.flush(FilterWriter.java:112)
    at org.mule.providers.http.ResponseWriter.flush(ResponseWriter.java:75)

I have searched internet but none of the trace or case seem to be fit with mine. I have tried to generate situation in my development environment (on windows.) Tried big messages, closed socket situations, 0 size messages, but no luck. Can not see the same error. Do anybody has any clue why this error can occur ? This is a bug in application or os bug ?

cacert
  • 2,237
  • 6
  • 28
  • 50
  • Did you already try `-Djava.net.preferIPv4Stack=true` ? It seems to be a solution on similar questions. – user140547 Jul 01 '15 at 13:36
  • @user140547 It would be nice if you could add a link to one of the _similar questions_ – MalaKa Jul 01 '15 at 13:47
  • http://stackoverflow.com/questions/8216713/java-net-socketexception-invalid-argument-connect http://stackoverflow.com/questions/3056399/eclipse-and-tomcat – user140547 Jul 01 '15 at 13:50
  • I already saw that question, stack trace does not look like mine(I get error in writing to socket). and also I get this error very rare, but the question specifies a permanent error I think. – cacert Jul 01 '15 at 18:30

1 Answers1

0

The problem (java.net.SocketException: Invalid argument) occurs when you try to write a buffer larger than 64K using SocketOutputStream.write(). When you use SocketOutputStream.write(), remenber use SocketOutputStream.flush() to clear SocketOutputStream.

Another situation, connection has closed by server. (use command 'netstat' to check status of your connection, will be 'CLOSE_WAIT') When you using SocketOutputStream.write(), log also dispaly "java.net.SocketException: Invalid argument".

REF_DOC

Johnny
  • 31
  • 4