nghttpx: Log error code from getsockopt(SO_ERROR) on first write event
This commit is contained in:
parent
bd0c1edaa6
commit
cf7f87c2ad
|
@ -1806,9 +1806,11 @@ int Http2Session::read_noop(const uint8_t *data, size_t datalen) { return 0; }
|
||||||
int Http2Session::write_noop() { return 0; }
|
int Http2Session::write_noop() { return 0; }
|
||||||
|
|
||||||
int Http2Session::connected() {
|
int Http2Session::connected() {
|
||||||
if (!util::check_socket_connected(conn_.fd)) {
|
auto sock_error = util::get_socket_error(conn_.fd);
|
||||||
|
if (sock_error != 0) {
|
||||||
SSLOG(WARN, this) << "Backend connect failed; addr="
|
SSLOG(WARN, this) << "Backend connect failed; addr="
|
||||||
<< util::to_numeric_addr(&addr_->addr);
|
<< util::to_numeric_addr(&addr_->addr)
|
||||||
|
<< ": errno=" << sock_error;
|
||||||
|
|
||||||
downstream_failure(addr_);
|
downstream_failure(addr_);
|
||||||
|
|
||||||
|
|
|
@ -1143,11 +1143,13 @@ int HttpDownstreamConnection::process_input(const uint8_t *data,
|
||||||
int HttpDownstreamConnection::connected() {
|
int HttpDownstreamConnection::connected() {
|
||||||
auto &connect_blocker = addr_->connect_blocker;
|
auto &connect_blocker = addr_->connect_blocker;
|
||||||
|
|
||||||
if (!util::check_socket_connected(conn_.fd)) {
|
auto sock_error = util::get_socket_error(conn_.fd);
|
||||||
|
if (sock_error != 0) {
|
||||||
conn_.wlimit.stopw();
|
conn_.wlimit.stopw();
|
||||||
|
|
||||||
DCLOG(WARN, this) << "Backend connect failed; addr="
|
DCLOG(WARN, this) << "Backend connect failed; addr="
|
||||||
<< util::to_numeric_addr(&addr_->addr);
|
<< util::to_numeric_addr(&addr_->addr)
|
||||||
|
<< ": errno=" << sock_error;
|
||||||
|
|
||||||
downstream_failure(addr_);
|
downstream_failure(addr_);
|
||||||
|
|
||||||
|
|
|
@ -259,10 +259,12 @@ int LiveCheck::initiate_connection() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int LiveCheck::connected() {
|
int LiveCheck::connected() {
|
||||||
if (!util::check_socket_connected(conn_.fd)) {
|
auto sock_error = util::get_socket_error(conn_.fd);
|
||||||
|
if (sock_error != 0) {
|
||||||
if (LOG_ENABLED(INFO)) {
|
if (LOG_ENABLED(INFO)) {
|
||||||
LOG(INFO) << "Backend connect failed; addr="
|
LOG(INFO) << "Backend connect failed; addr="
|
||||||
<< util::to_numeric_addr(&addr_->addr);
|
<< util::to_numeric_addr(&addr_->addr)
|
||||||
|
<< ": errno=" << sock_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -203,15 +203,16 @@ int MemcachedConnection::initiate_connection() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int MemcachedConnection::connected() {
|
int MemcachedConnection::connected() {
|
||||||
if (!util::check_socket_connected(conn_.fd)) {
|
auto sock_error = util::get_socket_error(conn_.fd);
|
||||||
|
if (sock_error != 0) {
|
||||||
|
MCLOG(WARN, this) << "memcached connect failed; addr="
|
||||||
|
<< util::to_numeric_addr(addr_)
|
||||||
|
<< ": errno=" << sock_error;
|
||||||
|
|
||||||
connect_blocker_.on_failure();
|
connect_blocker_.on_failure();
|
||||||
|
|
||||||
conn_.wlimit.stopw();
|
conn_.wlimit.stopw();
|
||||||
|
|
||||||
if (LOG_ENABLED(INFO)) {
|
|
||||||
MCLOG(INFO, this) << "memcached connect failed";
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
10
src/util.cc
10
src/util.cc
|
@ -893,6 +893,16 @@ bool check_socket_connected(int fd) {
|
||||||
return error == 0;
|
return error == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int get_socket_error(int fd) {
|
||||||
|
int error;
|
||||||
|
socklen_t len = sizeof(error);
|
||||||
|
if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len) != 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
bool ipv6_numeric_addr(const char *host) {
|
bool ipv6_numeric_addr(const char *host) {
|
||||||
uint8_t dst[16];
|
uint8_t dst[16];
|
||||||
return inet_pton(AF_INET6, host, dst) == 1;
|
return inet_pton(AF_INET6, host, dst) == 1;
|
||||||
|
|
|
@ -574,6 +574,11 @@ int create_nonblock_socket(int family);
|
||||||
|
|
||||||
bool check_socket_connected(int fd);
|
bool check_socket_connected(int fd);
|
||||||
|
|
||||||
|
// Returns the error code (errno) by inspecting SO_ERROR of given
|
||||||
|
// |fd|. This function returns the error code if it succeeds, or -1.
|
||||||
|
// Returning 0 means no error.
|
||||||
|
int get_socket_error(int fd);
|
||||||
|
|
||||||
// Returns true if |host| is IPv6 numeric address (e.g., ::1)
|
// Returns true if |host| is IPv6 numeric address (e.g., ::1)
|
||||||
bool ipv6_numeric_addr(const char *host);
|
bool ipv6_numeric_addr(const char *host);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue