wudisheng opened a new issue, #1860:
URL: https://github.com/apache/incubator-brpc/issues/1860

   **Describe the bug (描述bug)**
   
[`m->SetFailed()`](https://github.com/apache/incubator-brpc/blob/1.1.0/src/brpc/input_messenger.cpp#L227)
 is called with `saved_errno == 0` in 
[`InputMessenger::OnNewMessages()`](https://github.com/apache/incubator-brpc/blob/1.1.0/src/brpc/input_messenger.cpp#L180),
 which then triggers a hard error at [`CHECK(false) << "error_code is 
0"`](https://github.com/apache/incubator-brpc/blob/1.1.0/src/brpc/socket.cpp#L809).
   
   **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()`](https://github.com/apache/incubator-brpc/blob/1.1.0/src/butil/iobuf.cpp#L1585)
 may return `-1` with `errno == 0` in 
[`pappend_from_file_descriptor()`](https://github.com/apache/incubator-brpc/blob/1.1.0/src/butil/iobuf.cpp#L1551),
 which then cause
   - 
[`m->DoRead()`](https://github.com/apache/incubator-brpc/blob/1.1.0/src/brpc/input_messenger.cpp#L213)
 returns `nr == -1` with `errno == 0` in 
[`InputMessenger::OnNewMessages()`](https://github.com/apache/incubator-brpc/blob/1.1.0/src/brpc/input_messenger.cpp#L180),
 which then run into
   - [`else if (errno != 
EAGAIN)`](https://github.com/apache/incubator-brpc/blob/1.1.0/src/brpc/input_messenger.cpp#L221)
 branch with `errno == 0` and triggers the `CHECK` failure.
   
   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)`](https://github.com/apache/incubator-brpc/blob/1.1.0/src/brpc/input_messenger.cpp#L222)
 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 (更多上下文/截图)**
   
   <img width="1750" alt="20220727045020" 
src="https://user-images.githubusercontent.com/8771316/181109426-7ed7245b-78f0-4fde-81aa-871e233f9154.png";>
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to