Server closed websocket connection

 @param code [Integer]
 @param reason [String]
424135
def on_close(code, reason)
      debug "Server closed connection with code #{code}: #{reason}"

      case code
      when 4001
        handle_invalid_token
      when 4010
        handle_invalid_version(reason)
      when 4040, 4041
        handle_invalid_connection(reason)
      else
        warn "connection closed with code #{code}: #{reason}"
      end
    end
1031386
public static void sendCloseBlocking(final int code, String reason, final WebSocketChannel wsChannel) throws IOException {
        sendCloseBlocking(new CloseMessage(code, reason), wsChannel);
    }
1254524
function (code) {
              if (isLast) {
                if (code) {
                  reject(result)
                } else {
                  resolve(result)
                }
                return
              }
              var nextClose = pipes[idx + 1] && pipes[idx + 1].close
              if (nextClose) {
                nextClose()
              }
            }
1260787
def close(self, code: int = None, reason: str = None) -> None:
        """"""
        if not self.server_terminated:
            if not self.stream.closed():
                if code is None and reason is not None:
                    code = 1000  # "normal closure" status code
                if code is None:
                    close_data = b""
                else:
                    close_data = struct.pack(">H", code)
                if reason is not None:
                    close_data += utf8(reason)
                try:
                    self._write_frame(True, 0x8, close_data)
                except StreamClosedError:
                    self._abort()
            self.server_terminated = True
        if self.client_terminated:
            if self._waiting is not None:
                self.stream.io_loop.remove_timeout(self._waiting)
                self._waiting = None
            self.stream.close()
        elif self._waiting is None:
            # Give the client a few seconds to complete a clean shutdown,
            # otherwise just close the connection.
            self._waiting = self.stream.io_loop.add_timeout(
                self.stream.io_loop.time() + 5, self._abort
            )
721210
function(event) {
            event = event || {code: 1000};
            _cometd._debug('WebSocket onclose', context, event, 'connecting', _connecting, 'current', _context);

            if (context.connectTimer) {
                self.clearTimeout(context.connectTimer);
            }

            self.onClose(context, event);
        }
446270
@Override
    public void setStatus(int code, String reason) {
        this.response.setStatus(code);
        this.response.setReason(reason);
    }
140627
def send_close(self, status=STATUS_NORMAL, reason=six.b("")):
        
        if status < 0 or status >= ABNF.LENGTH_16:
            raise ValueError("code is invalid range")
        self.connected = False
        self.send(struct.pack('!H', status) + reason, ABNF.OPCODE_CLOSE)
1235355
protected void postCloseEvent(final WebSocketCloseCode closeCode, final String reason) {
        for (final WebSocketListener listener : listeners) {
            if (listener.onClose(this, closeCode, reason)) {
                break;
            }
        }
    }
523909
public void close(ErrorCode rstStatusCode, @Nullable IOException errorException)
      throws IOException {
    if (!closeInternal(rstStatusCode, errorException)) {
      return; // Already closed.
    }
    connection.writeSynReset(id, rstStatusCode);
  }
1188937
def connectionLost(self, reason):
        
        for wref in self._weakProxies.valuerefs():
            p = wref()
            if p is not None:
                p.connectionLost(reason)
124132
public void closeLater(ErrorCode errorCode) {
    if (!closeInternal(errorCode, null)) {
      return; // Already closed.
    }
    connection.writeSynResetLater(id, errorCode);
  }
823667
def do_close(self, reason):
        """"""
        if self.closed:
            return
        self.closed = True
        self.reason = reason
        self.incoming.close()
        self.responses.close()
        if not self._closing:
            self.client.channel_failed(self, Failure(reason))
306415
def connection_lost(self, exc: Optional[Exception]) -> None:
        
        logger.debug("%s - event = connection_lost(%s)", self.side, exc)
        self.state = State.CLOSED
        logger.debug("%s - state = CLOSED", self.side)
        if not hasattr(self, "close_code"):
            self.close_code = 1006
        if not hasattr(self, "close_reason"):
            self.close_reason = ""
        logger.debug(
            "%s x code = %d, reason = %s",
            self.side,
            self.close_code,
            self.close_reason or "[no reason]",
        )
        self.abort_keepalive_pings()
        # If self.connection_lost_waiter isn't pending, that's a bug, because:
        # - it's set only here in connection_lost() which is called only once;
        # - it must never be canceled.
        self.connection_lost_waiter.set_result(None)
        super().connection_lost(exc)
684912
@OnClose
    public void onClose(Session session, CloseReason closeReason)
    {
        logger.info("WebSocket closed. : SessionId={}, Reason={}", session.getId(),
                closeReason.toString());
        AmLogServerAdapter.getInstance().onClose(session);
    }
528165
@Override
    public void processClose(WebSocketChannel channel, int code, String reason) {
        LOG.entering(CLASS_NAME, "close");

        //2. check current readyState
        WebSocketCompositeChannel parent = (WebSocketCompositeChannel)channel;

        // When the connection timeout expires due to network loss, we first
        // invoke doClose() to inform the application immediately. Then, we
        // invoke processClose() to close the connection but it may take a
        // while to return. When doClose() is invoked, readyState is set to
        // CLOSED. However, we do want processClose() to be invoked all the
        // all the way down to close the connection. That's why we are no
        // longer throwing an exception here if readyState is CLOSED.
        
        if (!parent.closing) {
            parent.closing = true;
            parent.readyState = ReadyState.CLOSING;
            
            try {
                WebSocketSelectedChannel selectedChannel = parent.selectedChannel;
                selectedChannel.handler.processClose(selectedChannel, code, reason);                
            }
            catch (Exception e) {
                doClose(parent, false, CloseCommandMessage.CLOSE_ABNORMAL, e.getMessage());
            }
        }
    }
610297
protected final void onClose( final boolean wasClean,
                                final int code,
                                @Nullable final String reason )
  {
    getListener().onClose( this, wasClean, code, reason );
  }
9121
def closed(self, reason):
        """"""
        self.client.remove_connection(self)
        self.protocol.connection_lost(reason)
        if not isinstance(reason, ConnectionClosed):
            logger.warn("connection closed, reason {}".format(reason))
        else:
            logger.info("connection closed")