Program: 10693
Project: 10693
Buggy source:
public void connectIfNecessary() throws IOException {
  lock.tryLockTimeout("String_Node_Str");
  try {
    if (((wsSession == null) || !wsSession.isOpen()) && !isClosed()) {
      log.debug("String_Node_Str",label,url);
      try {
        if (client == null) {
          client=new WebSocketClient(sslContextFactory);
          client.setConnectTimeout(this.connectionTimeout);
          WebSocketPolicy policy=client.getPolicy();
          policy.setMaxBinaryMessageBufferSize(MAX_PACKET_SIZE);
          policy.setMaxTextMessageBufferSize(MAX_PACKET_SIZE);
          policy.setMaxBinaryMessageSize(MAX_PACKET_SIZE);
          policy.setMaxTextMessageSize(MAX_PACKET_SIZE);
          client.start();
        }
 else {
          log.debug("String_Node_Str",label);
        }
        if (heartbeating) {
          enableHeartbeat();
        }
        WebSocketClientSocket socket=new WebSocketClientSocket();
        ClientUpgradeRequest request=new ClientUpgradeRequest();
        wsSession=client.connect(socket,new URI(url),request).get(this.connectionTimeout,TimeUnit.MILLISECONDS);
        wsSession.setIdleTimeout(this.idleTimeout);
      }
 catch (      TimeoutException e) {
        fireConnectionFailed();
        this.closeClient();
        throw new KurentoException(label + "String_Node_Str" + this.connectionTimeout+ "String_Node_Str"+ url);
      }
catch (      Exception e) {
        fireConnectionFailed();
        this.closeClient();
        throw new KurentoException(label + "String_Node_Str" + url,e);
      }
      try {
        if (!latch.await(this.connectionTimeout,TimeUnit.MILLISECONDS)) {
          fireConnectionFailed();
          this.closeClient();
          throw new KurentoException(label + "String_Node_Str" + this.connectionTimeout+ "String_Node_Str"+ url);
        }
        if (session == null) {
          session=new ClientSession(null,null,JsonRpcClientWebSocket.this);
          handlerManager.afterConnectionEstablished(session);
        }
 else {
          try {
            rsHelper.sendRequest(METHOD_RECONNECT,String.class);
            log.info("String_Node_Str",label,url);
            fireReconnectedSameServer();
          }
 catch (          JsonRpcErrorException e) {
            if (e.getCode() == 40007) {
              rsHelper.setSessionId(null);
              rsHelper.sendRequest(METHOD_RECONNECT,String.class);
              pendingRequests.closeAllPendingRequests();
              log.info("String_Node_Str",label,url);
              fireReconnectedNewServer();
            }
 else {
              log.warn("String_Node_Str",label,url,e);
            }
          }
        }
      }
 catch (      InterruptedException e) {
        Thread.currentThread().interrupt();
      }
    }
  }
 catch (  TimeoutRuntimeException e) {
    log.error("String_Node_Str",label,url,e);
    this.closeClient();
  }
 finally {
    lock.unlock();
  }
}

Fixed version (ground truth):
public void connectIfNecessary() throws IOException {
  lock.tryLockTimeout("String_Node_Str");
  try {
    if (((wsSession == null) || !wsSession.isOpen()) && !isClosed()) {
      log.debug("String_Node_Str",label,url);
      try {
        if (client == null) {
          client=new WebSocketClient(sslContextFactory);
          client.setConnectTimeout(this.connectionTimeout);
          WebSocketPolicy policy=client.getPolicy();
          policy.setMaxBinaryMessageBufferSize(MAX_PACKET_SIZE);
          policy.setMaxTextMessageBufferSize(MAX_PACKET_SIZE);
          policy.setMaxBinaryMessageSize(MAX_PACKET_SIZE);
          policy.setMaxTextMessageSize(MAX_PACKET_SIZE);
          client.start();
          if (keepAliveManager == null && keepAliveTime != 0) {
synchronized (this) {
              if (keepAliveManager == null) {
                keepAliveManager=new KeepAliveManager(this,keepAliveTime,KeepAliveManager.Mode.PER_CLIENT);
                keepAliveManager.start();
              }
            }
          }
        }
 else {
          log.debug("String_Node_Str",label);
        }
        if (heartbeating) {
          enableHeartbeat();
        }
        WebSocketClientSocket socket=new WebSocketClientSocket();
        ClientUpgradeRequest request=new ClientUpgradeRequest();
        wsSession=client.connect(socket,new URI(url),request).get(this.connectionTimeout,TimeUnit.MILLISECONDS);
        wsSession.setIdleTimeout(this.idleTimeout);
      }
 catch (      TimeoutException e) {
        fireConnectionFailed();
        this.closeClient();
        throw new KurentoException(label + "String_Node_Str" + this.connectionTimeout+ "String_Node_Str"+ url);
      }
catch (      Exception e) {
        fireConnectionFailed();
        this.closeClient();
        throw new KurentoException(label + "String_Node_Str" + url,e);
      }
      try {
        if (!latch.await(this.connectionTimeout,TimeUnit.MILLISECONDS)) {
          fireConnectionFailed();
          this.closeClient();
          throw new KurentoException(label + "String_Node_Str" + this.connectionTimeout+ "String_Node_Str"+ url);
        }
        if (session == null) {
          session=new ClientSession(null,null,JsonRpcClientWebSocket.this);
          handlerManager.afterConnectionEstablished(session);
        }
 else {
          try {
            rsHelper.sendRequest(METHOD_RECONNECT,String.class);
            log.info("String_Node_Str",label,url);
            fireReconnectedSameServer();
          }
 catch (          JsonRpcErrorException e) {
            if (e.getCode() == 40007) {
              rsHelper.setSessionId(null);
              rsHelper.sendRequest(METHOD_RECONNECT,String.class);
              pendingRequests.closeAllPendingRequests();
              log.info("String_Node_Str",label,url);
              fireReconnectedNewServer();
            }
 else {
              log.warn("String_Node_Str",label,url,e);
            }
          }
        }
      }
 catch (      InterruptedException e) {
        Thread.currentThread().interrupt();
      }
    }
  }
 catch (  TimeoutRuntimeException e) {
    log.error("String_Node_Str",label,url,e);
    this.closeClient();
  }
 finally {
    lock.unlock();
  }
}