chenBright commented on code in PR #3745:
URL: https://github.com/apache/brpc/pull/3745#discussion_r4577141938
##########
src/brpc/rdma/rdma_endpoint.cpp:
##########
@@ -449,29 +481,62 @@ static int WriteToFdLoop(size_t len, WriteOnce&&
write_once, WaitWritable&& wait
int RdmaEndpoint::WriteToFd(void* data, size_t len) {
CHECK(data != nullptr);
Socket* s = _socket;
- const int fd = s->fd();
- return WriteToFdLoop(len,
+ int fd = s->fd();
+ return WriteToFdLoop(s, s->_connect_deadline_us, len,
[data, fd](size_t offset, size_t remaining) {
return write(fd, (uint8_t*)data + offset, remaining);
},
[s, fd](const timespec* duetime) {
- return s->WaitEpollOut(fd, true, duetime) == 0 || errno ==
ETIMEDOUT;
+ return s->WaitEpollOut(fd, true, duetime, false) == 0 ||
+ errno == ETIMEDOUT;
});
}
int RdmaEndpoint::WriteToFd(butil::IOBuf* data) {
CHECK(data != nullptr);
Socket* s = _socket;
- const int fd = s->fd();
- return WriteToFdLoop(data->size(),
+ int fd = s->fd();
+ return WriteToFdLoop(s, s->_connect_deadline_us, data->size(),
[data, fd](size_t /*offset*/, size_t /*remaining*/) {
return data->cut_into_file_descriptor(fd);
},
[s, fd](const timespec* duetime) {
- return s->WaitEpollOut(fd, true, duetime) == 0 || errno ==
ETIMEDOUT;
+ return s->WaitEpollOut(fd, true, duetime, false) == 0 ||
+ errno == ETIMEDOUT;
});
}
+int RdmaEndpoint::ReconnectForHandshake() {
+ Socket* s = _socket;
+ timespec duetime;
+ if (GetHandshakeWaitTime(s, s->_connect_deadline_us, &duetime) != 0) {
+ return -1;
+ }
+ timespec deadline =
butil::microseconds_to_timespec(s->_connect_deadline_us);
+ // Use Socket::Connect to preserve the configured device/local address and
+ // socket options. Keep ownership of the old fd until replacement succeeds.
+ butil::fd_guard new_fd(s->Connect(
+ s->_connect_deadline_us >= 0 ? &deadline : nullptr,
+ nullptr, nullptr, /*check_failed=*/true));
+ if (new_fd < 0 ||
+ GetHandshakeWaitTime(s, s->_connect_deadline_us, &duetime) != 0) {
+ return -1;
+ }
+ int old_fd = s->fd();
+ if (s->_transport->HasOnEdgeTrigger()) {
+ s->_io_event.RemoveConsumer(old_fd);
+ }
+ if (s->ResetFileDescriptor(new_fd) != 0) {
+ // ResetFileDescriptor clears `_fd` on error. Retain the old fd so
normal
+ // Socket recycling closes it and balances the connection counter.
+ s->_fd.store(old_fd, butil::memory_order_release);
+ return -1;
+ }
+ new_fd.release();
Review Comment:
Fixed by adding a post-registration check before committing the fd
replacement. If cancellation or timeout is detected, we remove the new fd from
the event dispatcher, restore the old fd, close the new fd, and return the
original error.
The handshake holds a Socket reference throughout this operation, preventing
recycling or health-check reset during rollback.
--
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]