OnIOError is called when the connection experiences
a low-level TCP transport error
@param Connection $conn
@param \Exception $ex
@return void
505048
public function onIOError(Connection $conn, \Exception $ex)
    {
        $this->onPublishResponse($conn, "IO_ERROR", $ex);

        try {
            $this->lookup->removeConnection($conn);
            $conn->tryClose();
        } catch (\Throwable $ignore) {
            sys_echo("nsq({$conn->getAddr()}) onIOError exception: {$ex->getMessage()}");
        } catch (\Exception $ignore) {
            sys_echo("nsq({$conn->getAddr()}) onIOError exception: {$ex->getMessage()}");
        }
    }
181296
public static function handle(CommunicationException $exception)
    {
        if ($exception->shouldResetConnection()) {
            $connection = $exception->getConnection();

            if ($connection->isConnected()) {
                $connection->disconnect();
            }
        }

        throw $exception;
    }
310726
public static function printException(\Exception $ex)
    {
        $msg="code:".$ex->getCode()
            ."\r\nmessage:".$ex->getMessage()
            ."\r\ntrace:".$ex->getTraceAsString();
        self::printLine($msg);
    }
1225623
public boolean isConnectionError(SQLException ex) {
        final boolean isTraceOn = TraceComponent.isAnyTracingEnabled();

        if (isTraceOn && tc.isEntryEnabled())
            Tr.entry(this, tc, "isConnectionError", ex);

        // Maintain a set in order to check for cycles
        Set<Throwable> chain = new HashSet<Throwable>();

        boolean stale = false;
        for (Throwable t = ex; t != null && !stale && chain.add(t); t = t.getCause()) {
            SQLException sqlX = t instanceof SQLException ? (SQLException) t : null;
            if (isTraceOn && tc.isDebugEnabled())
                Tr.debug(this, tc, "checking " + t,
                         sqlX == null ? null : sqlX.getSQLState(),
                         sqlX == null ? null : sqlX.getErrorCode());
            if (sqlX != null)
                stale |= sqlX instanceof SQLRecoverableException ||
                         sqlX instanceof SQLNonTransientConnectionException ||
                         sqlX instanceof SQLTransientConnectionException && failoverOccurred(sqlX) ||
                         staleErrorCodes.contains(sqlX.getErrorCode()) ||
                         staleSQLStates.contains(sqlX.getSQLState());
        }

        if (isTraceOn && tc.isEntryEnabled())
            Tr.exit(this, tc, "isConnectionError", stale);

        return stale;
    }
33774
public function exceptionHandler(Exception $ex)
    {
        return $this->errorHandler(E_USER_ERROR, $ex->getMessage(), $ex->getFile(), $ex->getLine());
    }
769677
public static function setConnection($con, $env = null) 
    {
        $env = self::selectEnvironment($env);
        self::$_connection[$env] = $con;

        // just send an exception when not on production mode
        if (in_array($env, array("development","test"))) {
            self::setErrorHandling(\PDO::ERRMODE_EXCEPTION);
        }
    }
861422
public final void closeConnection(final Connection conn) {
        try {
            if (conn != null) {
                conn.close();
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
246639
public function detach($conn)
    {
        parent::detach($conn);
        if ($this->overload) {
            if (!$this->maxConcurrency || ($this->count() < $this->maxConcurrency)) {
                $this->overload = false;
                $this->enable();
            }
        }
    }
720791
protected function setErrorCallback(ConnectionInterface $connection, callable $callback)
    {
        $connection->setErrorCallback(function ($connection, $exception) use ($callback) {
            \call_user_func($callback, $this, $exception, $connection);
        });
    }
652162
private static function handleRequestException (Throwable $ex) {
        ob_clean();
        $response = get_response();
        $response->clear();
        $errorRoutes = self::$errorRoutes->getRoutes();
        if (!empty($errorRoutes)) {
            foreach ($errorRoutes as $errorRoute) {
                $routeResult = self::executeAction($errorRoute->getAction(), array_merge($_REQUEST, $errorRoute->getParameters(), [Throwable::class => $ex, Exception::class => $ex]));
                if (!empty($routeResult)) {
                    $response->content($routeResult);
                }
            }
            $response->send();
        }
        else {
            throw $ex;
        }
    }
785392
protected function exception(ConnectionInterface $connection, ErrorResponseInterface $response)
    {
        $connection->disconnect();
        $message = $response->getMessage();

        throw new ServerException($message);
    }
476348
public function exceptionThrown(Swift_Events_TransportExceptionEvent $evt)
    {
        if ($this->bag->get('pd_mailer.logger_active')) {
            // Update Data
            $this->log->setStatus(\Swift_Events_SendEvent::RESULT_FAILED);
            $this->log->addException($evt->getException()->getMessage() . PHP_EOL);

            // Update
            $this->entityManager->persist($this->log);
            $this->entityManager->flush();
        }
    }
501960
protected function tryAgainIfCausedByLostConnection(Exception $e, $dsn, $username, $password, $options)
    {
        if ($this->causedByLostConnection($e)) {
            return $this->createPdoConnection($dsn, $username, $password, $options);
        }

        throw $e;
    }
1024321
protected function processException(RequestException $exception): void
    {
        $requestContents = $this->getContentsFromMessage($exception->getRequest());
        $responseContents = $this->getContentsFromMessage($exception->getResponse());

        if ($exception instanceof ConnectException) {
            throw new ConnectionException($exception->getMessage(), $requestContents, $exception);
        } else {
            $message = $this->extractMessageFromErrorResponse($responseContents, $exception->getMessage());
            $statusCode = 0;
            if ($exception->getResponse() instanceof PsrResponseInterface) {
                $statusCode = $exception->getResponse()->getStatusCode();
            }

            throw $this->createApiClientException($statusCode, $message, $requestContents, $responseContents);
        }
    }
1251414
function onMessage(ProcConnection $conn, $data) {
        if ($this->_status == self::STATUS_INIT)
            return;
        $data = self::_parseTex($data);
        if ($data === false)
            return;
        if ($this->_status == self::STATUS_FORMULA) {
            $this->_formula = $data;
            $this->_id = self::genPic($data);
            $this->_status = self::STATUS_RESULT;
            $conn->send($this->_current->withEval());
        } else {
            $message = $this->_current->getMessage();
            msg_send(Captcha::getQueue(), 1, [$this->_id, $message, $data]);
            if (msg_stat_queue(Captcha::getQueue())['msg_qnum'] < Config::get('CAPTCHA_CACHE_MAX')) {
                $this->generate();
            } else {
                $this->_status = self::STATUS_INIT;
            }
        }
    }
409631
public function onResponse(Connection $conn, $bytes)
    {
        $this->onPublishResponse($conn, $bytes);

        if ($bytes === "CLOSE_WAIT") {
            // nsqd ack客户端的StartClose, 准备关闭
            // 可以假定不会再收到任何nsqd的消息
            $conn->tryClose();
        }
    }
1325656
public function onSocketConnect($socket, Connection $connection): void
    {
        $this->checkConnections($connection);
        $this->checkConnectionsPerIp($connection);
    }