Adding SocketChannel toString to connection exception messages
stevenschlansker at gmail.com
Thu Dec 21 19:11:50 UTC 2017
While tracking down a connectivity issue, we identified that two of our hosts
are unable to talk to each other due to a misconfiguration of the network.
This manifested as:
2017-12-21T11:00:34.840Z DEBUG <> [default-pool-34] o.e.j.client.AbstractConnectionPool - Connection 1/32 creation failed
java.net.ConnectException: Connection refused
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
The message, 'Connection refused', does tell you something -- but it doesn't emit
really any information about what actually happened (i.e. host / port of refused connection)
that would allow you to track down exactly where it failed.
While the application can generally figure this out (it probably knows where it tried to connect)
the SocketChannelImpl could helpfully attach this information to the message, rather than relying
on the application to correctly figure out the information at every connect point.
What if ConnectException included the attempted hostname / IP / port SocketAddress?
java.net.ConnectException: Connection to 'foo.mycorp.com[10.x.x.x]:12345' refused
Much more useful! This could also be extended to various other socket exceptions.
Would such a contribution be accepted?
Thanks for considering!
More information about the core-libs-dev