Bug 42585 - SocketNode can leak Sockets
Summary: SocketNode can leak Sockets
Alias: None
Product: Log4j - Now in Jira
Classification: Unclassified
Component: Other (show other bugs)
Version: unspecified
Hardware: Other Linux
: P2 major
Target Milestone: ---
Assignee: log4j-dev
: 46324 (view as bug list)
Depends on:
Reported: 2007-06-05 05:08 UTC by Ortwin Glueck
Modified: 2009-01-08 09:34 UTC (History)
1 user (show)

patch (983 bytes, patch)
2007-06-05 06:32 UTC, Ortwin Glueck
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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
	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.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.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]
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. ***