this event only happens when the connection is lost physically, which cannot be tested automatically; removing from coverage: istanbul ignore next
169145
function onError(err) {
    const ctx = this.$ctx;
    const cn = npm.utils.getSafeConnection(ctx.cn);
    npm.events.error(ctx.options, err, {cn, dc: ctx.dc});
    ctx.disconnect(err);
    if (ctx.cnOptions && typeof ctx.cnOptions.onLost === 'function' && !ctx.notified) {
        try {
            ctx.cnOptions.onLost.call(this, err, {
                cn,
                dc: ctx.dc,
                start: ctx.start,
                client: this
            });
        } catch (e) {
            npm.con.error(e && e.stack || e);
        }
        ctx.notified = true;
    }
}
147360
def on_disconnect(self, code, stream_name, reason):
        """"""
        logger.error('Disconnect message: %s %s %s', code, stream_name, reason)
        return True
1276434
def _on_server_disconnect(self, exception):
        """"""
        self._protocol = None
        if self._on_disconnect_callback_func and callable(self._on_disconnect_callback_func):
            self._on_disconnect_callback_func(exception)
        if self._reconnect:
            self._reconnect_cb()
499919
function onConnect(err) {
    if (err) {
      DEBUG("connect error", err)
      return cb(err)
    }

    DEBUG("connected")

    channel.sendMessage({
      type: "request",
      name: "connect",
      to:   "server",
      id:   "0",
      body: {
        key: config.key
      }
    })
  }
307160
public void connectionClosed(javax.sql.ConnectionEvent event) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled())
            Tr.event(this, tc, "connectionClosed", "Notification of connection closed received from the JDBC driver", AdapterUtil.toString(event.getSource()));

        // We have intentionally removed our connection event listener prior to closing the
        // underlying connection. Therefore, if this event ever occurs, it indicates a
        // scenario where the connection has been closed unexpectedly by the JDBC driver
        // or database. We will treat this as a connection error.
        if(isAborted()) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                Tr.debug(this, tc, "The connection was aborted, so this event will not be processed");
        } else {
            processConnectionErrorOccurredEvent(null, event.getSQLException());
        }
    }
473012
public void connectionFreed(IManagedConnectionEvent<C> event) {
        IPhynixxManagedConnection<C> proxy = event.getManagedConnection();
        if (!proxy.hasCoreConnection()) {
            return;
        } else {
            this.freeConnection(proxy);
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug("Proxy " + proxy + " released");
        }

    }
9652
def connection_lost(self, exc):
        """"""
        if exc:
            log.exception('disconnected due to exception')
        else:
            log.info('disconnected because of close/abort.')
        if self.disconnect_callback:
            self.disconnect_callback(exc)
1022467
private void onConnectFailed(){
        LOGGER.info("Socket failed");
        isConnecting = false;
        isConnected = false;
        cleanup();
        synchronized(connectHolder){
            connectHolder.notifyAll();
        }
    }
308747
function () {
        stopHeartBeatInterval(ortc);

        reconnectStartedAt = null;
        isConnected = false;
        isConnecting = false;
        validatedArrived = false;
        retryingWithSsl = false;        

        clearValidatedTimeout(self);

        if (ortc.sockjs != null) {
            ortc.sockjs.close();
            ortc.sockjs = null;
        }
    }
1370771
function(error) {
        Strophe.error("Websocket error " + error);
        this._conn._changeConnectStatus(Strophe.Status.CONNFAIL, "The WebSocket connection could not be established was disconnected.");
        this._disconnect();
    }
1301810
def connection_lost(self, exception):
        
        if isinstance(exception, Exception):
            logger.debug('Connection to port `%s` lost: %s', self.port,
                         exception)
        else:
            logger.debug('Connection to port `%s` closed', self.port)
        self.connected.clear()
        self.disconnected.set()
102665
def on_disconnect(self):
        ""
        if self._stream is not None:
            self._stream = None
        if self._buffer is not None:
            self._buffer.close()
            self._buffer = None
        self.encoding = None
168674
protected void checkIfAlreadyConnected(DeviceProxy device, String attribute, String event_name, CallBack callback, int max_size, boolean stateless)
            throws DevFailed {
        if (device == null || (callback == null && max_size < 0)) {
            Except.throw_wrong_syntax_exception("API_InvalidArgs",
                    "Device or callback pointer NULL and  event queue not used !!",
                    "EventConsumer.subscribe_event()");
        }

        if (device == null || device.name() == null)
            Except.throw_event_system_failed("API_NotificationServiceFailed",
                    "Failed to connect to device",
                    "EventConsumer.subscribe_event()");
        else {
            //	Check if already connected (exists in map)
            String callback_key = device.name().toLowerCase() + "/" + attribute + "." + event_name;
            if (event_callback_map.containsKey(callback_key))
                Except.throw_event_system_failed("API_MethodArgument",
                        "Already connected to event " + callback_key,
                        "EventConsumer.subscribe_event()");

            //	Check if already trying to connects (exists in map)
            if (stateless && failed_event_callback_map.containsKey(callback_key))
                Except.throw_event_system_failed("API_MethodArgument",
                        "Already trying to connect to event " + callback_key,
                        "EventConsumer.subscribe_event()");
        }
    }
1024018
function () {
        reconnectStartedAt = null;
        isConnecting = false;
        if (ortc.sockjs && ortc.sockjs != null) {
            ortc.sockjs.close();
            ortc.sockjs = null;
        }
    }
1358277
function (callback) {
            debug('');

            self.eventStore.on('connect', function () {
              self.emit('connect');
            });

            self.eventStore.on('disconnect', function () {
              self.emit('disconnect');
            });

            self.eventStore.init(callback);
          }
1008171
public void unableToSend(String nodeID, LinkedList<byte[]> packets, Throwable cause) {
		if (nodeID != null) {
			executor.execute(() -> {

				// Debug
				if (debug) {
					logger.warn("Unable to send message to \"" + nodeID + "\".", cause);
				}

				// Mark endpoint as offline
				NodeDescriptor node = nodes.get(nodeID);
				boolean disconnected = false;
				if (node != null) {
					node.writeLock.lock();
					try {
						if (node != null && node.markAsOffline()) {

							// Remove actions and listeners
							registry.removeActions(nodeID);
							eventbus.removeListeners(nodeID);
							writer.close(node.nodeID);
							disconnected = true;

						}
					} catch (Exception error) {
						logger.warn("Unable to turn off node!", error);
					} finally {
						node.writeLock.unlock();
					}
				}
				if (node != null && disconnected) {

					// Notify listeners (unexpected disconnection)
					logger.info("Node \"" + nodeID + "\" disconnected.");
					broadcastNodeDisconnected(node.info, true);
				}

				// Send error back to the source
				if (packets != null) {
					FastBuildTree errorMap = null;
					if (cause != null) {

						// Convert to Throwable to MoleculerError
						MoleculerError moleculerError;
						if (cause instanceof MoleculerError) {
							moleculerError = (MoleculerError) cause;
						} else {
							String message = String.valueOf(cause.getMessage());
							message = message.replace('\r', ' ').replace('\n', ' ').trim();
							moleculerError = new MoleculerError(message, cause, "MoleculerError", nodeID, false, 500,
									"UNKNOWN_ERROR");
						}

						// Convert MoleculerError to JSON
						errorMap = new FastBuildTree(8);
						moleculerError.toTree(errorMap);
					}
					for (byte[] packet : packets) {
						try {

							// Remove header
							if (packet != null && packet.length > 6) {
								byte[] copy = new byte[packet.length - 6];
								System.arraycopy(packet, 6, copy, 0, copy.length);

								// Deserialize packet
								Tree message = serializer.read(copy);

								// Get request's unique ID
								String id = message.get("id", (String) null);
								if (id == null || id.isEmpty()) {

									// Not a request
									return;
								}

								// Create response message
								FastBuildTree response = new FastBuildTree(6);
								response.putUnsafe("id", id);
								response.putUnsafe("ver", ServiceBroker.PROTOCOL_VERSION);
								response.putUnsafe("sender", nodeID);
								response.putUnsafe("success", false);
								response.putUnsafe("data", (String) null);
								if (errorMap != null) {
									response.putUnsafe("error", errorMap);
								}
								registry.receiveResponse(response);
							}
						} catch (Exception error) {
							logger.warn("Unable to handle error!", error);
						}
					}
				}
			});
		}
	}
523619
function _connectionFailureHandler(self) {
      return function() {
        if (this._connectionFailHandled) return;
        this._connectionFailHandled = true;
        // Destroy the connection
        this.destroy();
        // Count down the number of reconnects
        self.retriesLeft = self.retriesLeft - 1;
        // How many retries are left
        if (self.retriesLeft <= 0) {
          // Destroy the instance
          self.destroy();
          // Emit close event
          self.emit(
            'reconnectFailed',
            new MongoNetworkError(
              f(
                'failed to reconnect after %s attempts with interval %s ms',
                self.options.reconnectTries,
                self.options.reconnectInterval
              )
            )
          );
        } else {
          self.reconnectId = setTimeout(attemptReconnect(self), self.options.reconnectInterval);
        }
      };
    }