Thrift error logging improvements
Summary: - Move strerror_s to Thrift.h (was previously in TTransportException.h)
- Capture errno as soon as syscall returns failure and make it part of error message.
- Cleaned up several instances of the wrong error value being printed.
- More consistently pass the errno in the TTransport Exception
- Add more consistent error logging for the various transport failure modes
Reviewed By: dreiss
Test Plan: - compile everything.
- test on search tier
Revert: OK
TracCamp Project: Thrift
DiffCamp Revision: 11077
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665648 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/server/TNonblockingServer.cpp b/lib/cpp/src/server/TNonblockingServer.cpp
index c840bcc..ebe85a6 100644
--- a/lib/cpp/src/server/TNonblockingServer.cpp
+++ b/lib/cpp/src/server/TNonblockingServer.cpp
@@ -50,10 +50,12 @@
// Signal completion back to the libevent thread via a socketpair
int8_t b = 0;
if (-1 == send(taskHandle_, &b, sizeof(int8_t), 0)) {
- GlobalOutput("TNonblockingServer::Task: send");
+ string errStr = "TNonblockingServer::Task: send " + TOutput::strerror_s(errno);
+ GlobalOutput(errStr.c_str());
}
if (-1 == ::close(taskHandle_)) {
- GlobalOutput("TNonblockingServer::Task: close, possible resource leak");
+ string errStr = "TNonblockingServer::Task: close, possible resource leak " + TOutput::strerror_s(errno);
+ GlobalOutput(errStr.c_str());
}
}
@@ -139,7 +141,8 @@
}
if (errno != ECONNRESET) {
- GlobalOutput("TConnection::workSocket() recv -1");
+ string errStr = "TConnection::workSocket() recv -1 " + TOutput::strerror_s(errno);
+ GlobalOutput(errStr.c_str());
}
}
@@ -175,7 +178,8 @@
return;
}
if (errno != EPIPE) {
- GlobalOutput("TConnection::workSocket() send -1");
+ string errStr = "TConnection::workSocket() send -1 " + TOutput::strerror_s(errno);
+ GlobalOutput(errStr.c_str());
}
close();
return;
@@ -221,7 +225,8 @@
// We are setting up a Task to do this work and we will wait on it
int sv[2];
if (-1 == socketpair(AF_LOCAL, SOCK_STREAM, 0, sv)) {
- GlobalOutput("TConnection::socketpair() failed");
+ string errStr = "TConnection::socketpair() failed " + TOutput::strerror_s(errno);
+ GlobalOutput(errStr.c_str());
// Now we will fall through to the APP_WAIT_TASK block with no response
} else {
// Create task and dispatch to the thread manager
@@ -519,7 +524,8 @@
int flags;
if ((flags = fcntl(clientSocket, F_GETFL, 0)) < 0 ||
fcntl(clientSocket, F_SETFL, flags | O_NONBLOCK) < 0) {
- GlobalOutput("thriftServerEventHandler: set O_NONBLOCK");
+ string errStr = "thriftServerEventHandler: set O_NONBLOCK (fcntl) " + TOutput::strerror_s(errno);
+ GlobalOutput(errStr.c_str());
close(clientSocket);
return;
}
@@ -542,7 +548,8 @@
// Done looping accept, now we have to make sure the error is due to
// blocking. Any other error is a problem
if (errno != EAGAIN && errno != EWOULDBLOCK) {
- GlobalOutput("thriftServerEventHandler: accept()");
+ string errStr = "thriftServerEventHandler: accept() " + TOutput::strerror_s(errno);
+ GlobalOutput(errStr.c_str());
}
}
@@ -564,7 +571,8 @@
// Wildcard address
error = getaddrinfo(NULL, port, &hints, &res0);
if (error) {
- GlobalOutput("TNonblockingServer::serve() getaddrinfo");
+ string errStr = "TNonblockingServer::serve() getaddrinfo " + string(gai_strerror(error));
+ GlobalOutput(errStr.c_str());
return;
}