This is an automated email from the ASF dual-hosted git repository.
chenBright pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brpc.git
The following commit(s) were added to refs/heads/master by this push:
new 9329eddd6 fix(ubshm): preserve IPC mappings after unlink (#3729)
9329eddd6 is described below
commit 9329eddd644bde939bc575631752a395feb459c9
Author: nkysg <[email protected]>
AuthorDate: Sat Nov 21 11:19:11 2026 +0800
fix(ubshm): preserve IPC mappings after unlink (#3729)
---
src/brpc/ubshm/shm/shm_ipc.cpp | 1 -
test/brpc_ubring_unittest.cpp | 18 ++++++++++++++++++
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/src/brpc/ubshm/shm/shm_ipc.cpp b/src/brpc/ubshm/shm/shm_ipc.cpp
index f0a9d7ea1..0e20e3a57 100644
--- a/src/brpc/ubshm/shm/shm_ipc.cpp
+++ b/src/brpc/ubshm/shm/shm_ipc.cpp
@@ -133,7 +133,6 @@ RETURN_CODE IpcShmFree(SHM *shm)
}
if (errno == ENOENT) {
LOG(INFO) << "IPC free shm=" << shm->name << " already deleted.";
- shm->addr = nullptr;
return SHM_ERR_NOT_FOUND;
}
LOG_EVERY_SECOND(ERROR) << "IPC free shm=" << shm->name << " failed,
errno=" << errno;
diff --git a/test/brpc_ubring_unittest.cpp b/test/brpc_ubring_unittest.cpp
index 558c69664..f4f5c3657 100644
--- a/test/brpc_ubring_unittest.cpp
+++ b/test/brpc_ubring_unittest.cpp
@@ -28,9 +28,11 @@
#include "brpc/socket.h"
#if BRPC_WITH_UBRING
+#include <unistd.h>
#include "brpc/ubshm/common/common.h"
#include "brpc/ubshm/ub_endpoint.h"
#include "brpc/ubshm/shm/shm_def.h"
+#include "brpc/ubshm/shm/shm_ipc.h"
#include "brpc/ubshm/shm/shm_mgr.h"
#include "brpc/ubshm/ub_ring_manager.h"
#include "brpc/ubshm/ub_ring.h"
@@ -882,6 +884,22 @@ TEST_F(UBShmEndpointTest,
allocate_client_resources_real_shm) {
EXPECT_EQ(0, ret);
}
+TEST_F(UBShmEndpointTest, repeated_ipc_unlink_keeps_mapping_for_unmap) {
+ static std::atomic<uint32_t> name_sequence(0);
+ const std::string name = "/brpc_u_" + std::to_string(getpid()) + "_" +
+ std::to_string(name_sequence.fetch_add(1, std::memory_order_relaxed));
+ brpc::ubring::SHM shm = {nullptr, 4096, 0, {0}, (uint32_t)_socket->fd()};
+ ASSERT_LT(name.size(), sizeof(shm.name));
+ memcpy(shm.name, name.c_str(), name.size() + 1);
+ ASSERT_EQ(0, brpc::ubring::IpcShmLocalMalloc(&shm));
+ uint8_t* const addr = shm.addr;
+
+ ASSERT_EQ(0, brpc::ubring::IpcShmFree(&shm));
+ EXPECT_EQ(SHM_ERR_NOT_FOUND, brpc::ubring::IpcShmFree(&shm));
+ EXPECT_EQ(addr, shm.addr);
+ EXPECT_EQ(0, brpc::ubring::IpcShmMunmap(&shm));
+}
+
TEST_F(UBShmEndpointTest, reset_cleans_up_resources) {
brpc::ubring::SHM local_trx_shm =
{nullptr, 4 * 1024 * 1024, 0, {0}, (uint32_t)_socket->fd()};
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]