Describe the bug (描述bug)
m->SetFailed() is called with saved_errno == 0 in InputMessenger::OnNewMessages(), which then triggers a hard error at CHECK(false) << "error_code is 0".
To Reproduce (复现方法)
In our environment we can constantly reproduce this issue in LTO (-flto=full) and ThinLTO (-flto=thin) modes, but everything runs without error in normal (-fno-lto) mode.
I surfed a bit into the source code, and it turns out that
By adding several pieces of logging codes with cares taken not to unintentionally change errno, I can confirm the behavior described above, see the attached screenshot for reference.
A potential fix / workaround is to change if (errno == EINTR) to if (error == 0 || errno == EINTR), but I'm not familiar with BRPC code (nor did I figure out why link-time optimization triggers such an issue), so I'd prefer BRPC maintainers taking a look at it. Thanks!
Expected behavior (期望行为)
Consistent behavior regardless of link-time optimization options.
Versions (各种版本)
OS: Linux Ubuntu 18.04 in Docker
Compiler: Clang 12.0.1
brpc: 1.1.0 Release
protobuf: 21.1
Additional context/screenshots (更多上下文/截图)

Describe the bug (描述bug)
m->SetFailed()is called withsaved_errno == 0inInputMessenger::OnNewMessages(), which then triggers a hard error atCHECK(false) << "error_code is 0".To Reproduce (复现方法)
In our environment we can constantly reproduce this issue in LTO (
-flto=full) and ThinLTO (-flto=thin) modes, but everything runs without error in normal (-fno-lto) mode.I surfed a bit into the source code, and it turns out that
readv()may return-1witherrno == 0inpappend_from_file_descriptor(), which then causem->DoRead()returnsnr == -1witherrno == 0inInputMessenger::OnNewMessages(), which then run intoelse if (errno != EAGAIN)branch witherrno == 0and triggers theCHECKfailure.By adding several pieces of logging codes with cares taken not to unintentionally change
errno, I can confirm the behavior described above, see the attached screenshot for reference.A potential fix / workaround is to change
if (errno == EINTR)toif (error == 0 || errno == EINTR), but I'm not familiar with BRPC code (nor did I figure out why link-time optimization triggers such an issue), so I'd prefer BRPC maintainers taking a look at it. Thanks!Expected behavior (期望行为)
Consistent behavior regardless of link-time optimization options.
Versions (各种版本)
OS: Linux Ubuntu 18.04 in Docker
Compiler: Clang 12.0.1
brpc: 1.1.0 Release
protobuf: 21.1
Additional context/screenshots (更多上下文/截图)