Skip to content

Conversation

@barspi
Copy link
Contributor

@barspi barspi commented Dec 26, 2025

When ISOServer was unable to bind to the server port, it was catching a generic Throwable and generating a generic jPOS ThrowableAuditLogEvent.

Also, a one-liner of the exception was being logged as info, but with no clue as to which port failed.

<log realm="xyz.server" at="2025..." trace-id="aa1995.......">
  <info>
    java.net.BindException: Address already in use (s.n.c.Net.bind0:-2,s.n.c.Net.bind:522,s.n.c.Net.bind:511,s.n.c.NioSocketImpl.bind:641,j.n.ServerSocket.bind:326,o.j.i.ISOServer.createServerSocket:283,o.j.i.ISOServer.run:492,j.u.c.Executors$RunnableAdapter.call:545,j.u.c.FutureTask.run:328,j.u.c.ThreadPerTaskExecutor$ThreadBoundFuture.run:323)
  </info>
</log>

This PR

  • Extends org.jpos.log.evt.Listen with a possible error message (unrendered if null)
  • Catches a specific BindException
  • Generates the same Listen jPOS event that is thrown in the successful case (when bind succeeds), but with an error message (and inside a warn LogEvent instead of an info).
    This has two advantages:
    • The Listen event already carries port number, bind address, etc.
    • This mimics the behaviour of the client BaseChannel which uses the Connect event both in the succesful and failed case, giving an error in the second case.

This is an example in the traditional jPOS log format when it fails

<log realm="xyz.server" at="2025..." trace-id="599bd...">
  <warn>
    Listen[port=2324, bindAddr=localhost/127.0.0.1, permits=100, backlog=5, error='(round 14) java.net.BindException: Address already in use']
  </warn>
</log>

The round (indicating attempt) was added for extra info, because the variable was available and not being used ;-)

This has also been tested with structured logging and it looks fine. For example (pretty printed)

{
  "ts": "2025-12-26T22:11:43.849597Z",
  "realm": "xyz.server",
  "tag": "warn",
  "trace-id": "1b1406f246b74053b4240fd8c01a5712",
  "evt": [
    {
      "t": "listen",
      "port": 2324,
      "bindAddr": "localhost",
      "permits": 100,
      "backlog": 5,
      "error": "(round 14) java.net.BindException: Address already in use"
    }
  ]
}

@ar ar merged commit 83f9261 into jpos:main Dec 29, 2025
2 checks passed
@barspi barspi deleted the isoserver-catch-bind-exception branch December 29, 2025 22:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants