Integration java.net.SocketTimeoutException: connect timed out error
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-25-2022 03:08 AM
Hello,
I'm working on an integration via MID server and I keep getting the 'java.net.SocketTimeoutException: connect timed out' error. I read and asked around, what seems to be the solution is changing the default timeout value in the MID server config.xm file. I applied that but the instance is still throwing the same error. Below I post a screen show of how it looks.
Basically, I think that increasing the timeout limit can fix the issue. How to increase the wait time?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2023 10:46 PM
Your Java socket is timing out (throws java.net.SocketTimeoutException: Connection timed out) means that it takes too long to get respond from other device and your request expires before getting response.
You can effectively handle it from client side by define a connection timeout and later handle it by using a try/catch/finally block. You can use the connect(SocketAddress endpoint, int timeout) method and set the timeout parameter:
Socket socket = new Socket();
SocketAddress socketAddress = new InetSocketAddress(host, port);
socket.connect(socketAddress, 12000); //12000 are milli seconds
From server side you can use the setSoTimeout(int timeout) method to set a timeout value. The timeout value defines how long the ServerSocket.accept() method will block:
ServerSocket serverSocket = new new ServerSocket(port);
serverSocket.setSoTimeout(12000);
So to avoid this exception in another way, you should keep the connection be alive using the method Socket.setKeepAlive() method although possibly you have not used the method setTimeout() , meaning asking the socket to unlimited block to receive.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2023 10:49 PM
@Kub Please check the ACLs on target table
ServiceNow Community Rising Star, Class of 2023