Bug 42585

Summary: SocketNode can leak Sockets
Product: Log4j - Now in Jira Reporter: Ortwin Glueck <odi>
Component: OtherAssignee: log4j-dev <log4j-dev>
Status: RESOLVED FIXED    
Severity: major CC: jon
Priority: P2    
Version: unspecified   
Target Milestone: ---   
Hardware: Other   
OS: Linux   
Attachments: patch

Description Ortwin Glueck 2007-06-05 05:08:09 UTC
We had an issue when the SocketNode thread died with an OOM exception. The
socket is not closed in this case. The sending SocketAppender doesn't notice and
blocks indefinitely in SocketOutputStream.write. Due to the locks held on the
appender this causes the whole application to block.

One solution should be to close the the socket in a finally block. Of course we
are also adding size checks to the problematic log statement plus increasing the
heap size of the logserver.

"Dispatcher-Thread-3" daemon prio=1 tid=0x5b6b6120 nid=0x6c8e runnable
[0x5b16f000..0x5b16f770]
	at java.net.SocketOutputStream.socketWrite0(Native Method)
	at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
	at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
	at
java.io.ObjectOutputStream$BlockDataOutputStream.drain(ObjectOutputStream.java:1682)
	at
java.io.ObjectOutputStream$BlockDataOutputStream.setBlockDataMode(ObjectOutputStream.java:1591)
	at java.io.ObjectOutputStream.writeNonProxyDesc(ObjectOutputStream.java:1173)
	at java.io.ObjectOutputStream.writeClassDesc(ObjectOutputStream.java:1127)
	at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1284)
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1079)
	at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:302)
	at org.apache.log4j.net.SocketAppender.append(SocketAppender.java:224)
	at org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:221)
	- locked <0x66a9c690> (a org.apache.log4j.net.SocketAppender)
	at
org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:57)
	at org.apache.log4j.Dispatcher.run(AsyncAppender.java:310)
	- locked <0x66a9a060> (a org.apache.log4j.helpers.AppenderAttachableImpl)
Comment 1 Ortwin Glueck 2007-06-05 06:32:26 UTC
Created attachment 20312 [details]
patch
Comment 2 Curt Arnold 2007-06-05 16:28:10 UTC
Fixed in rev 544675.  Should make it into log4j 1.2.15.  run method didn't check if ois or socket was null 
before doing actions on them so I added checks in addition to your suggested changes.
Comment 3 Ortwin Glueck 2007-06-06 00:38:36 UTC
Fantastic, thanks a lot.
Comment 4 Curt Arnold 2009-01-08 09:34:51 UTC
*** Bug 46324 has been marked as a duplicate of this bug. ***