Skip to content

Commit

Permalink
Remap folly exception for read/write errors
Browse files Browse the repository at this point in the history
Map network errors back to std::system_error instead of
folly's own exception

Change-Id: I328c999f126257ac4f37d3229c742badd57c11a9
Reviewed-on: http://review.couchbase.org/c/kv_engine/+/159773
Reviewed-by: Dave Rigby <daver@couchbase.com>
Tested-by: Build Bot <build@couchbase.com>
  • Loading branch information
trondn committed Aug 20, 2021
1 parent dc009f7 commit eff9e89
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions protocol/connection/client_connection.cc
Expand Up @@ -562,7 +562,7 @@ class WriteCallback : public folly::AsyncWriter::WriteCallback {
};

void MemcachedConnection::sendBuffer(const std::vector<iovec>& list) {
if (packet_dump || true) {
if (packet_dump) {
for (const auto& entry : list) {
sendBuffer({reinterpret_cast<const uint8_t*>(entry.iov_base),
entry.iov_len});
Expand All @@ -579,9 +579,9 @@ void MemcachedConnection::sendBuffer(const std::vector<iovec>& list) {
if (writeCallback.exception) {
if (writeCallback.exception->getType() ==
folly::AsyncSocketException::END_OF_FILE) {
throw std::system_error(int(std::errc::connection_reset),
std::system_category(),
"network error");
throw std::system_error(
std::make_error_code(std::errc::connection_reset),
"network error");
}
if (writeCallback.exception->getType() ==
folly::AsyncSocketException::NETWORK_ERROR) {
Expand Down Expand Up @@ -612,6 +612,18 @@ void MemcachedConnection::sendBuffer(cb::const_byte_buffer buf) {
"pump");
}
if (writeCallback.exception) {
if (writeCallback.exception->getType() ==
folly::AsyncSocketException::END_OF_FILE) {
throw std::system_error(
std::make_error_code(std::errc::connection_reset),
"network error");
}
if (writeCallback.exception->getType() ==
folly::AsyncSocketException::NETWORK_ERROR) {
throw std::system_error(writeCallback.exception->getErrno(),
std::system_category(),
"network error");
}
throw *writeCallback.exception;
}
}
Expand Down Expand Up @@ -724,11 +736,18 @@ void MemcachedConnection::recvFrame(Frame& frame,

if (!asyncReadCallback->getNextFrame()) {
if (asyncReadCallback->eof) {
throw std::system_error(int(std::errc::connection_reset),
std::system_category(),
"EOF");
throw std::system_error(
std::make_error_code(std::errc::connection_reset), "EOF");
}
if (asyncReadCallback->exception) {
if (asyncReadCallback->exception->getType() ==
folly::AsyncSocketException::NETWORK_ERROR) {
throw std::system_error(
asyncReadCallback->exception->getErrno(),
std::system_category(),
"network error");
}

throw *asyncReadCallback->exception;
}

Expand Down Expand Up @@ -780,9 +799,8 @@ void MemcachedConnection::recvFrame(Frame& frame,
const auto* next = asyncReadCallback->getNextFrame();
if (next == nullptr) {
if (asyncReadCallback->eof) {
throw std::system_error(int(std::errc::connection_reset),
std::system_category(),
"EOF");
throw std::system_error(
std::make_error_code(std::errc::connection_reset), "EOF");
}
if (asyncReadCallback->exception) {
throw *asyncReadCallback->exception;
Expand Down

0 comments on commit eff9e89

Please sign in to comment.