Program: 10728
Project: 10728
Buggy source:
public void connectIfNecessary() throws IOException {
  lock.tryLockTimeout("String_Node_Str");
  try {
    if ((wsSession == null || !wsSession.isOpen()) && !clientClose) {
      log.debug("String_Node_Str",label,url);
      try {
        if (client == null) {
          client=new WebSocketClient(sslContextFactory);
          client.setConnectTimeout(this.connectionTimeout);
          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();
      }
    }
    log.debug("String_Node_Str",label,url);
  }
 catch (  TimeoutRuntimeException e) {
    log.error("String_Node_Str",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()) && !clientClose) {
      log.debug("String_Node_Str",label,url);
      try {
        if (client == null) {
          client=new WebSocketClient(sslContextFactory);
          client.setConnectTimeout(this.connectionTimeout);
          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",url,e);
    this.closeClient();
  }
 finally {
    lock.unlock();
  }
}