Skip to content
This repository was archived by the owner on Jul 12, 2023. It is now read-only.

Commit 5a384ad

Browse files
kc7bfij1elo
authored andcommitted
Allow timeout on handshake handler (#12)
* Allow timeout on handshake handler * Set thread name in cached executor * Add timeout to sync * Replace sync() with await()
1 parent 03890b8 commit 5a384ad

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

kurento-jsonrpc/kurento-jsonrpc-client/src/main/java/org/kurento/jsonrpc/client/JsonRpcClientNettyWebSocket.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,10 @@ protected void initChannel(SocketChannel ch) {
250250
final int maxRetries = 5;
251251
while (channel == null || !channel.isOpen()) {
252252
try {
253-
channel = b.connect(host, port).sync().channel();
254-
handler.handshakeFuture().sync();
253+
ChannelFuture connectFuture = b.connect(host, port);
254+
if (!connectFuture.await(this.connectionTimeout)) throw new WebSocketHandshakeException("Timeout");
255+
channel = connectFuture.channel();
256+
if (!handler.handshakeFuture().await(this.connectionTimeout)) throw new WebSocketHandshakeException("Timeout");
255257
} catch (InterruptedException e) {
256258
// This should never happen
257259
log.warn("{} ERROR connecting WS Netty client, opening channel", label, e);
@@ -298,7 +300,7 @@ private void closeChannel() {
298300
if (channel != null) {
299301
log.debug("{} Closing client", label);
300302
try {
301-
channel.close().sync();
303+
channel.close().await(this.connectionTimeout);
302304
} catch (Exception e) {
303305
log.debug("{} Could not properly close websocket client. Reason: {}", label, e.getMessage(),
304306
e);

kurento-jsonrpc/kurento-jsonrpc-server/src/main/java/org/kurento/jsonrpc/internal/ws/WebSocketServerSession.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import org.kurento.commons.PropertiesManager;
2929
import org.kurento.commons.exception.KurentoException;
30+
import org.kurento.commons.ThreadFactoryCreator;
3031
import org.kurento.jsonrpc.JsonRpcException;
3132
import org.kurento.jsonrpc.JsonUtils;
3233
import org.kurento.jsonrpc.TransportException;
@@ -56,7 +57,8 @@ public class WebSocketServerSession extends ServerSession {
5657

5758
private final PendingRequests pendingRequests = new PendingRequests();
5859

59-
private ExecutorService execService = Executors.newCachedThreadPool();
60+
private ExecutorService execService = Executors.newCachedThreadPool(
61+
ThreadFactoryCreator.create("WebSocketServerSession-async"));
6062

6163
public WebSocketServerSession(String sessionId, Object registerInfo,
6264
SessionsManager sessionsManager, WebSocketSession wsSession) {

0 commit comments

Comments
 (0)