void LibEventServer::onRequest(struct evhttp_request *request) { // If we are in the process of crashing, we want to reject incoming work. // This will prompt the load balancers to choose another server. Using // shutdown rather than close has the advantage that it makes fewer changes // to the process (eg, it doesn't close the FD so if the FD number were // corrupted it would be mostly harmless). // // Setting accept sock to -1 will leak FDs. But we're crashing anyways. if (IsCrashing) { if (m_accept_sock != -1) { shutdown(m_accept_sock, SHUT_FBLISTEN); m_accept_sock = -1; } if (m_accept_sock_ssl != -1) { shutdown(m_accept_sock_ssl, SHUT_FBLISTEN); m_accept_sock_ssl = -1; } return; } if (RuntimeOption::EnableKeepAlive && RuntimeOption::ConnectionTimeoutSeconds > 0) { // before processing request, set the connection timeout // it's just writing a variable in libevent evhttp_connection_set_timeout(request->evcon, RuntimeOption::ConnectionTimeoutSeconds); } if (getStatus() == RunStatus::RUNNING) { RequestPriority priority = getRequestPriority(request); m_dispatcher.enqueue(LibEventJobPtr(new LibEventJob(request)), priority); } else { Logger::Error("throwing away one new request while shutting down"); } }
void ProxygenServer::onRequest(std::shared_ptr<ProxygenTransport> transport) { if (IsCrashing) { Logger::Error("Discarding request while crashing"); if (m_shutdownState == ShutdownState::SHUTDOWN_NONE) { m_shutdownState = ShutdownState::DRAINING_READS; } m_httpServerSocket.reset(); m_httpsServerSocket.reset(); transport->abort(); return; } if (getStatus() == RunStatus::RUNNING || (getStatus() == RunStatus::STOPPING && m_shutdownState <= ShutdownState::DRAINING_READS)) { RequestPriority priority = getRequestPriority(transport->getUrl()); VLOG(4) << this << ": enqueing request with path=" << transport->getUrl() << " and priority=" << priority; m_enqueuedCount++; transport->setEnqueued(); m_dispatcher.enqueue(std::make_shared<ProxygenJob>(transport), priority); } else { // VM is shutdown transport->abort(); Logger::Error("%p: throwing away one new request while shutting down", this); } }