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

Allow timeout on handshake handler #12

Merged
merged 4 commits into from
Jul 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,10 @@ protected void initChannel(SocketChannel ch) {
final int maxRetries = 5;
while (channel == null || !channel.isOpen()) {
try {
channel = b.connect(host, port).sync().channel();
handler.handshakeFuture().sync();
ChannelFuture connectFuture = b.connect(host, port);
if (!connectFuture.await(this.connectionTimeout)) throw new WebSocketHandshakeException("Timeout");
channel = connectFuture.channel();
if (!handler.handshakeFuture().await(this.connectionTimeout)) throw new WebSocketHandshakeException("Timeout");
} catch (InterruptedException e) {
// This should never happen
log.warn("{} ERROR connecting WS Netty client, opening channel", label, e);
Expand Down Expand Up @@ -298,7 +300,7 @@ private void closeChannel() {
if (channel != null) {
log.debug("{} Closing client", label);
try {
channel.close().sync();
channel.close().await(this.connectionTimeout);
} catch (Exception e) {
log.debug("{} Could not properly close websocket client. Reason: {}", label, e.getMessage(),
e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import org.kurento.commons.PropertiesManager;
import org.kurento.commons.exception.KurentoException;
import org.kurento.commons.ThreadFactoryCreator;
import org.kurento.jsonrpc.JsonRpcException;
import org.kurento.jsonrpc.JsonUtils;
import org.kurento.jsonrpc.TransportException;
Expand Down Expand Up @@ -56,7 +57,8 @@ public class WebSocketServerSession extends ServerSession {

private final PendingRequests pendingRequests = new PendingRequests();

private ExecutorService execService = Executors.newCachedThreadPool();
private ExecutorService execService = Executors.newCachedThreadPool(
ThreadFactoryCreator.create("WebSocketServerSession-async"));

public WebSocketServerSession(String sessionId, Object registerInfo,
SessionsManager sessionsManager, WebSocketSession wsSession) {
Expand Down