Bug 8527 - TelnetAppender accept()ing on closed socket after reconfiguration
Summary: TelnetAppender accept()ing on closed socket after reconfiguration
Alias: None
Product: Log4j - Now in Jira
Classification: Unclassified
Component: Appender (show other bugs)
Version: 1.2
Hardware: Sun Solaris
: P3 normal
Target Milestone: ---
Assignee: log4j-dev
Depends on:
Reported: 2002-04-25 19:35 UTC by Gavin Panella
Modified: 2004-11-16 19:05 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Gavin Panella 2002-04-25 19:35:18 UTC
I'm using log4j-1.2-rc1.

I configure log4j using DOMConfigurator.configureAndWatch("foo.xml") to create 
a TelnetAppender.  I happily telnet to this and all is fine.  I edit foo.xml to 
change some small things, and when log4j notices the change and reconfigures, 
the telnet session is disconnected, but I can reconnect fine.  However, the old 
TelnetAppender appears to be lingering trying to accept() connections on it's, 
now closed, ServerSocket:

java.net.SocketException: Socket is closed
   at java.net.ServerSocket.accept(ServerSocket.java:405)
   at org.apache.log4j.net.TelnetAppender$SocketHandler.run 

It loops endlessly in a while(true) dumping the stack trace to the console.  
It's only effect (afaik) is to destroy performance (and potentially disk space 
if console output is being captured).

A obvious fix is to replace the while(true) to while(running), modifying this 
new flag just before the ServerSocket is closed.  This does result in a 
SocketException if the thread is blocked waiting for a connection, but this can 
be cleanly hidden by conditionally printing the error based on that same flag.

....... If an IOException other than an InterruptedIOException is thrown from 
accept() then is it not an indication of a 'broken' ServerSocket?  Perhaps 
allowing IOExceptions to propagate would be a better policy?
Comment 1 Ceki Gulcu 2002-05-09 19:53:57 UTC
Thanks the bug is now fixed.