Jetty
  1. Jetty
  2. JETTY-838

Excessive logging when server socket is in use (please don't log and throw)

    Details

    • Type: Improvement Improvement
    • Status: Resolved Resolved
    • Priority: Trivial Trivial
    • Resolution: Fixed
    • Affects Version/s: 6.1.14
    • Fix Version/s: 7.0.0.RC5, 6.1.20
    • Component/s: None
    • Labels:
      None
    • Environment:
      N/A
    • Number of attachments :
      0

      Description

      When Jetty is started in embedded mode with a server socket that is already in use, the BindException is printed three times. Two of the stack traces originate from AbstractLifeCycle.start and the third from the embedding program.

      Logging an exception and then rethrowing it makes error diagnostics harder, as there's extra noise in the logs. These messages cannot easily be turned of without affecting the overall logging of the application, so the user of Jetty is stuck with noisy logs. Error handling code should EITHER log OR throw.

      Here's an example:
      java.net.BindException: Address already in use: JVM_Bind
      at java.net.PlainSocketImpl.socketBind(Native Method)
      at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:359)
      at java.net.ServerSocket.bind(ServerSocket.java:319)
      at java.net.ServerSocket.<init>(ServerSocket.java:185)
      at java.net.ServerSocket.<init>(ServerSocket.java:141)
      at org.mortbay.jetty.bio.SocketConnector.newServerSocket(SocketConnector.java:80)
      at org.mortbay.jetty.bio.SocketConnector.open(SocketConnector.java:73)
      at org.mortbay.jetty.AbstractConnector.doStart(AbstractConnector.java:283)
      at org.mortbay.jetty.bio.SocketConnector.doStart(SocketConnector.java:147)
      at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
      at org.mortbay.jetty.Server.doStart(Server.java:233)
      at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
      at com.yahtzeeplayer.web.StartWebServer.main(StartWebServer.java:114)
      [WARNING] org.mortbay.log: failed Server@facf0b
      java.net.BindException: Address already in use: JVM_Bind
      at java.net.PlainSocketImpl.socketBind(Native Method)
      at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:359)
      at java.net.ServerSocket.bind(ServerSocket.java:319)
      at java.net.ServerSocket.<init>(ServerSocket.java:185)
      at java.net.ServerSocket.<init>(ServerSocket.java:141)
      at org.mortbay.jetty.bio.SocketConnector.newServerSocket(SocketConnector.java:80)
      at org.mortbay.jetty.bio.SocketConnector.open(SocketConnector.java:73)
      at org.mortbay.jetty.AbstractConnector.doStart(AbstractConnector.java:283)
      at org.mortbay.jetty.bio.SocketConnector.doStart(SocketConnector.java:147)
      at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
      at org.mortbay.jetty.Server.doStart(Server.java:233)
      at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
      at com.yahtzeeplayer.web.StartWebServer.main(StartWebServer.java:114)
      Exception in thread "main" java.net.BindException: Address already in use: JVM_Bind
      at java.net.PlainSocketImpl.socketBind(Native Method)
      at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:359)
      at java.net.ServerSocket.bind(ServerSocket.java:319)
      at java.net.ServerSocket.<init>(ServerSocket.java:185)
      at java.net.ServerSocket.<init>(ServerSocket.java:141)
      at org.mortbay.jetty.bio.SocketConnector.newServerSocket(SocketConnector.java:80)
      at org.mortbay.jetty.bio.SocketConnector.open(SocketConnector.java:73)
      at org.mortbay.jetty.AbstractConnector.doStart(AbstractConnector.java:283)
      at org.mortbay.jetty.bio.SocketConnector.doStart(SocketConnector.java:147)
      at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
      at org.mortbay.jetty.Server.doStart(Server.java:233)
      at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
      at com.yahtzeeplayer.web.StartWebServer.main(StartWebServer.java:114)

      To fix, remove line 56 in AbstractLifeCycle.java: "Log.warn("failed " + this,e);"

      Here is a complete list of calls to Log.warn that are accompanied by throwing new exceptions. Ideally, all of these logging statements should be removed:

      • org.mortbay.servlet.CGI.init line 165
      • org.mortbay.jetty.webapp.WebXmlConfiguration.initialize line 297
      • org.mortbay.jetty.security.SslSocketConnector.newServerSocket(String, int, int) line 461
      • org.mortbay.component.AbstractLifeCycle.start() line 56
      • org.mortbay.component.AbstractLifeCycle.start() line 62
      • org.mortbay.component.AbstractLifeCycle.stop() line 84
      • org.mortbay.component.AbstractLifeCycle.stop() line 90
      • org.mortbay.jetty.handler.ContextHandlerCollection.addContext(String, String) line 269
      • org.mortbay.jetty.servlet.Holder.doStart() line 78
      • org.mortbay.jetty.AbstractConnector.Acceptor.run() line 719
      • org.mortbay.jetty.handler.ContextHandler.setResourceBase(String) line 988
      • org.mortbay.jetty.handler.ResourceHandler.setResourceBase(String) line 130

        Activity

        Hide
        Greg Wilkins added a comment -

        probably can reduce these to just debugs.

        But will hold off on this until the future of jetty-7 is decided, so we don't have to do this in 3 branches.

        Show
        Greg Wilkins added a comment - probably can reduce these to just debugs. But will hold off on this until the future of jetty-7 is decided, so we don't have to do this in 3 branches.
        Hide
        Jan Bartel added a comment -

        Time to re-evaluate now the move to eclipse is more complete.

        Show
        Jan Bartel added a comment - Time to re-evaluate now the move to eclipse is more complete.
        Hide
        Greg Wilkins added a comment -

        fixed... better late than never.

        Show
        Greg Wilkins added a comment - fixed... better late than never.

          People

          • Assignee:
            Greg Wilkins
            Reporter:
            Johannes Brodwall
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: