You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by Ja...@fritolay.com on 2001/06/21 18:30:53 UTC

SocketNode - Unexpected Exception

I am somewhat new to log4j but am looking forward to gaining experience with it
and possibly contributing to the product itself. Being a totally blind
programmer, many interactive debugging tools are not productively useful to me
through my speech/Braille output software. However, log4j seems to give me a
controllable output which is very easy to read and understand.

I have setup a script on an AIX machine to run the SimpleSocketServer class and
configured my client application (running on Windows NT)  to send log records to
that server. The log records are coming through to the server just fine and
everything looks good until the client application ends. Then I get the error
message below on the output of the log server.

[2001-06-21 11:12:21]  net.SocketNode() - Unexpected exception. Closing
conneciton.
java.io.IOException: A connection with a remote socket was reset by that socket.
     at java.net.SocketInputStream.read(Compiled Code)
     at java.net.SocketInputStream.read(Compiled Code)
     at java.io.ObjectInputStream.peekCode(Compiled Code)
     at java.io.ObjectInputStream.refill(Compiled Code)
     at java.io.ObjectInputStream.readObject(Compiled Code)
     at java.io.ObjectInputStream.readObject(Compiled Code)
     at org.apache.log4j.net.SocketNode.run(Compiled Code)
     at java.lang.Thread.run(Compiled Code)

I have tried putting a finalize method in my application with a .shutdown() call
to the two category names being used.

Any feedback would be appreciated.



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-dev-help@jakarta.apache.org


Re: SocketNode - Unexpected Exception

Posted by Anders Kristensen <ak...@dynamicsoft.com>.

Ceki Gülcü wrote:
> [...]
> ps: Anders, I'll check this in unless you have another approach.

No, that's what I had in mind.

Cheers,
Anders

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-dev-help@jakarta.apache.org


Re: SocketNode - Unexpected Exception

Posted by Ceki Gülcü <cg...@qos.ch>.
Hello,

I think this issue is specific to the AIX VM. As Anders indicated the SocketNode loop does not expect to receive an IOException. However, if you study the code you will see that the error message is purely defensive. Nothing bad actually happens. 

One solution is to "expect" IOExceptions, to report them as an info message without the exception. Here is the new code:

---- SocketNode.java -----------

  public void run() {
    LoggingEvent event;
    Category remoteCategory;

    try {
      while(true) {     
        event = (LoggingEvent) ois.readObject();        
        remoteCategory = hierarchy.getInstance(event.categoryName);
        event.category = remoteCategory;
        if(event.priority.isGreaterOrEqual(remoteCategory.getChainedPriority())) {
          remoteCategory.callAppenders(event);  
        }
      }
    }
    catch(java.io.EOFException e) {
      cat.info("Caught java.io.EOFException closing conneciton.");
    } catch(java.net.SocketException e) {
      cat.info("Caught java.net.SocketException closing conneciton.");
    } catch(IOException e) {
      cat.info("Caught java.io.IOException: "+e); // it's a + not , 
      cat.info("Closing connection.");
    } catch(Exception e) {
      cat.error("Unexpected exception. Closing conneciton.", e);
    }

Regards, Ceki

ps: Anders, I'll check this in unless you have another approach.   

At 14:08 21.06.2001 -0400, Anders Kristensen wrote:


>Jay.Macarty@fritolay.com wrote:
>> 
>> I am somewhat new to log4j but am looking forward to gaining experience with it
>> and possibly contributing to the product itself. Being a totally blind
>> programmer, many interactive debugging tools are not productively useful to me
>> through my speech/Braille output software. However, log4j seems to give me a
>> controllable output which is very easy to read and understand.
>> 
>> I have setup a script on an AIX machine to run the SimpleSocketServer class and
>> configured my client application (running on Windows NT)  to send log records to
>> that server. The log records are coming through to the server just fine and
>> everything looks good until the client application ends. Then I get the error
>> message below on the output of the log server.
>> 
>> [2001-06-21 11:12:21]  net.SocketNode() - Unexpected exception. Closing
>> conneciton.
>> java.io.IOException: A connection with a remote socket was reset by that socket.
>>      at java.net.SocketInputStream.read(Compiled Code)
>>      at java.net.SocketInputStream.read(Compiled Code)
>>      at java.io.ObjectInputStream.peekCode(Compiled Code)
>>      at java.io.ObjectInputStream.refill(Compiled Code)
>>      at java.io.ObjectInputStream.readObject(Compiled Code)
>>      at java.io.ObjectInputStream.readObject(Compiled Code)
>>      at org.apache.log4j.net.SocketNode.run(Compiled Code)
>>      at java.lang.Thread.run(Compiled Code)
>
>The SimpleSocketServer handles EOFException and SocketExceptions as
>indicative of a graceful shutdown, but not IOExceptions. This is why it
>logs the exception stacktrace. This is probably not the best behaviour
>given that current log4j clients will not usually close the sockets
>before exiting.
>
>> 
>> I have tried putting a finalize method in my application with a .shutdown() call
>> to the two category names being used.
>
>Category.shutdown is a static method -- no point in invoking it twice.
>
>Cheers,
>Anders
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: log4j-dev-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: log4j-dev-help@jakarta.apache.org

--
Ceki Gülcü


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-dev-help@jakarta.apache.org


Re: SocketNode - Unexpected Exception

Posted by Anders Kristensen <ak...@dynamicsoft.com>.

Jay.Macarty@fritolay.com wrote:
> 
> I am somewhat new to log4j but am looking forward to gaining experience with it
> and possibly contributing to the product itself. Being a totally blind
> programmer, many interactive debugging tools are not productively useful to me
> through my speech/Braille output software. However, log4j seems to give me a
> controllable output which is very easy to read and understand.
> 
> I have setup a script on an AIX machine to run the SimpleSocketServer class and
> configured my client application (running on Windows NT)  to send log records to
> that server. The log records are coming through to the server just fine and
> everything looks good until the client application ends. Then I get the error
> message below on the output of the log server.
> 
> [2001-06-21 11:12:21]  net.SocketNode() - Unexpected exception. Closing
> conneciton.
> java.io.IOException: A connection with a remote socket was reset by that socket.
>      at java.net.SocketInputStream.read(Compiled Code)
>      at java.net.SocketInputStream.read(Compiled Code)
>      at java.io.ObjectInputStream.peekCode(Compiled Code)
>      at java.io.ObjectInputStream.refill(Compiled Code)
>      at java.io.ObjectInputStream.readObject(Compiled Code)
>      at java.io.ObjectInputStream.readObject(Compiled Code)
>      at org.apache.log4j.net.SocketNode.run(Compiled Code)
>      at java.lang.Thread.run(Compiled Code)

The SimpleSocketServer handles EOFException and SocketExceptions as
indicative of a graceful shutdown, but not IOExceptions. This is why it
logs the exception stacktrace. This is probably not the best behaviour
given that current log4j clients will not usually close the sockets
before exiting.

> 
> I have tried putting a finalize method in my application with a .shutdown() call
> to the two category names being used.

Category.shutdown is a static method -- no point in invoking it twice.

Cheers,
Anders

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-dev-help@jakarta.apache.org