chenBright commented on PR #3525:
URL: https://github.com/apache/brpc/pull/3525#issuecomment-5578283543
> ### 🔵 Needs a closer look
> The new fd-close polling helper in `test/brpc_socket_unittest.cpp` can be
flaky due to missing EINTR handling in the `fcntl(F_GETFD)` loop.
>
> Review details
> ### Suppressed comments (1)
> **test/brpc_socket_unittest.cpp:130**
>
> * WaitForClosedFd() polls fcntl(F_GETFD) but doesn’t handle EINTR; if a
signal interrupts fcntl, the loop may exit early and the final ASSERT expects
EBADF, causing flaky failures. Also, errno should be reset before the final
fcntl so the EBADF check is guaranteed to correspond to that call.
>
> ```
> void WaitForClosedFd(int fd) {
> for (int i = 0; i < 100 && fcntl(fd, F_GETFD) != -1; ++i) {
> bthread_usleep(10000);
> }
> ASSERT_EQ(-1, fcntl(fd, F_GETFD));
> ASSERT_EQ(EBADF, errno);
> }
> ```
>
> * **Files reviewed:** 18/18 changed files
> * **Comments generated:** 0 new
> * **Review effort level:** Lite
`fcntl` only returns `EINTR` for the blocking lock commands
(`F_SETLKW/F_OFD_SETLKW`);
`F_GETFD` just reads the `FD_CLOEXEC` bit from the fd table and can't be
interrupted, so
`EBADF` is its only realistic failure
--
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]