Skip to content

Commit 12195e2

Browse files
committed
fix: duplicate RDMA ACK fd before acquiring send stream
rdma_comm_sender::get_send_stream() receives a borrowed ACK fd from the replication layer. Duplicate it before wrapping it in rdma_comm::unique_fd so rdma_comm can take ownership without closing the caller-owned fd. Also document the borrowed-fd ownership contract in rdma_sender_base.
1 parent dd0998c commit 12195e2

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

src/limestone/rdma/rdma_comm/rdma_comm_sender.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
#include <rdma/rdma_comm_sender.h>
1717
#include <rdma/rdma_comm_send_stream.h>
1818

19+
#include <cerrno>
20+
#include <cstring>
21+
#include <string>
22+
#include <unistd.h>
23+
1924
#include <rdma_comm/unique_fd.h>
2025

2126
namespace limestone::replication {
@@ -33,9 +38,14 @@ rdma_sender_base::operation_result rdma_comm_sender::initialize(
3338
rdma_sender_base::stream_acquire_result rdma_comm_sender::get_send_stream(
3439
std::uint16_t channel_id,
3540
int ack_fd) noexcept {
41+
int owned_ack_fd = ::dup(ack_fd);
42+
if (owned_ack_fd < 0) {
43+
return {{false, std::string{"dup() failed for RDMA ACK fd: "} + std::strerror(errno)}, nullptr};
44+
}
45+
3646
auto r = sender_.get_send_stream(
3747
channel_id,
38-
rdma::communication::unique_fd{ack_fd});
48+
rdma::communication::unique_fd{owned_ack_fd});
3949
if (! r.status.success || ! r.stream) {
4050
return {{false, r.status.error_message}, nullptr};
4151
}

src/limestone/rdma/rdma_sender_base.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ class rdma_sender_base {
6666
/**
6767
* @brief Acquire a send stream for the given logical channel.
6868
* @param channel_id Logical channel identifier.
69-
* @param ack_fd File descriptor used to receive acknowledgements.
69+
* @param ack_fd Borrowed file descriptor used to receive acknowledgements.
70+
* Implementations must duplicate it before taking ownership.
7071
* @return stream_acquire_result; stream is non-null on success.
7172
*/
7273
[[nodiscard]] virtual stream_acquire_result get_send_stream(

0 commit comments

Comments
 (0)