 
         # The WebSocket was closed
         @sock.once 'close', =>
-          if @autoReconnect == true and @initiatedClose != true
+          if @autoReconnect == true
             @sock = null
 
             if @pingerRef?

    @pingerRef = null
    @messageCount = 0
    @lastMessageId = null
    @initiatedClose = false
    @autoReconnect = @cfg.websocket_auto_reconnect ? true

  # Shutdown the WebSocket for good (prevents auto-reconnect)


    if @sock?
      try
        @autoReconnect = false
        @sock.close()
      catch error
        logger.error "Error while closing WebSocket: #{error}\n#{error.stack}"
      finally
        @sock = null

  # Alias to the close() method
  disconnect: -> @close()
