Skip to content

Commit 43400d7

Browse files
Merge pull request #876 from BLasan/5.3.x
Handle: Socket Timeout Exception
2 parents 0a347b6 + 52a733e commit 43400d7

File tree

1 file changed

+25
-2
lines changed
  • components/data-bridge/org.wso2.carbon.databridge.receiver.binary/src/main/java/org/wso2/carbon/databridge/receiver/binary/internal

1 file changed

+25
-2
lines changed

components/data-bridge/org.wso2.carbon.databridge.receiver.binary/src/main/java/org/wso2/carbon/databridge/receiver/binary/internal/BinaryDataReceiver.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import java.io.*;
4343
import java.net.ServerSocket;
4444
import java.net.Socket;
45+
import java.net.SocketTimeoutException;
4546
import java.nio.ByteBuffer;
4647
import java.security.KeyManagementException;
4748
import java.security.KeyStore;
@@ -210,12 +211,23 @@ public BinarySecureEventServerAcceptor(ServerSocket serverSocket) {
210211
@Override
211212
public void run() {
212213
while (true) {
214+
Socket socket = null;
213215
try {
214-
Socket socket = this.serverSocket.accept();
216+
socket = this.serverSocket.accept();
215217
socket.setSoTimeout(binaryDataReceiverConfiguration.getSocketTimeout());
216218
sslReceiverExecutorService.submit(new BinaryTransportReceiver(socket));
219+
} catch (SocketTimeoutException socketTimeoutException) {
220+
log.error("Socket read timed out for client", socketTimeoutException);
217221
} catch (IOException e) {
218222
log.error("Error while accepting the connection. ", e);
223+
} finally {
224+
if (socket != null && !socket.isClosed()) {
225+
try {
226+
socket.close();
227+
} catch (IOException ex) {
228+
log.error("Error while closing socket", ex);
229+
}
230+
}
219231
}
220232
}
221233
}
@@ -231,12 +243,23 @@ public BinaryEventServerAcceptor(ServerSocket serverSocket) {
231243
@Override
232244
public void run() {
233245
while (true) {
246+
Socket socket = null;
234247
try {
235-
Socket socket = this.serverSocket.accept();
248+
socket = this.serverSocket.accept();
236249
socket.setSoTimeout(binaryDataReceiverConfiguration.getSocketTimeout());
237250
tcpReceiverExecutorService.submit(new BinaryTransportReceiver(socket));
251+
} catch (SocketTimeoutException socketTimeoutException) {
252+
log.error("Socket read timed out for client", socketTimeoutException);
238253
} catch (IOException e) {
239254
log.error("Error while accepting the connection. ", e);
255+
} finally {
256+
if (socket != null && !socket.isClosed()) {
257+
try {
258+
socket.close();
259+
} catch (IOException ex) {
260+
log.error("Error while closing socket", ex);
261+
}
262+
}
240263
}
241264
}
242265
}

0 commit comments

Comments
 (0)