65 Commits

Author SHA1 Message Date
Regal 58ad9048b9 build: complete UBRING Bazel and CI support (#3445)
Add the missing BRPC_WITH_UBRING Bazel configuration, wire it through
the library and example targets, and document the supported build
commands.

Enable RDMA and UBRING in CI jobs whose all-options configurations did
not exercise those features. Run both feature suites in the existing
Bazel unit-test jobs and enable RDMA in the Make unit-test job.

Use unsigned literals for UBRING atomic counter operations to match the
counter type and avoid template deduction failures on stricter
compilers.

Signed-off-by: Zhengwei Zhu <141622927+ZhengweiZhu@users.noreply.github.com>
2026-08-15 09:54:19 +08:00
Xiaofeng Wang ce0eaec391 Merge pull request #3429 from wasphin/feature/protobuf-35
Support Protobuf v35
2026-08-09 19:42:20 +08:00
Bright Chen 7a3e034e20 Fix brpc_proto_library failure when brpc is used as an external Bazel dependency (#3427) 2026-08-09 14:47:53 +08:00
Yang,Liming 6a8bbc7f92 Merge pull request #3352 from chenBright/ece
Support end-to-end ECE negotiation in RDMA handshake V3
2026-07-21 17:02:50 +08:00
Chuang Zhang 72bf13a395 Interconnecting with the UBShmTransport Based on the LD/ST Shared Memory Semantics. (#3290)
* add ubring transport

* fix the  bug for ub ring transport

* fix the  bug for ub ring transport and other

* add the license for ub transport

* Modifying the variable naming style

* optimize the log message and some field name

* fix some bug for ubring

* add some log ubring endpoint

* add todo

* fix the bug for handshake for ub endpoint

* fix the bug for client ub endpoint

* optimize the iobuf file code

* modify the log level

* fix the declare_shm_ubs define not found bug

* add the timer_mgr support for macos and format code style

* fix the bug for macos epoll

* fix the timespece bug

* adaptor the itimerspec for macos platform

* optimize the cmakelist config

* add the ubring docs for ubring transport

* modify some file name and directory structure

* modify some code style and optimize code logical

* add the cmake ubshm transport ci/testing

* add the dependency header

* bug fix the code

* Fix UB shm allocation cleanup crashes (#11)

Co-authored-by: 郭业昌 <lvpengfei@MacBook-Air.local>

* remove the brpc_ubshm_unittest

* Found and fixed two stability issues (#13)

* 修复ubring server端关闭连接coredump问题

* 修复PollIn/PollOut解引用已释放Socket指针的问题

PollIn/PollOut通过ep->_socket(裸指针)读取data socket,当data socket
被销毁时该指针悬空,导致Socket::Address读到垃圾id触发SIGSEGV。
改为存储_socket_id(SocketId),用Address获取引用计数的Socket,
并在整个回调期间持有该引用,避免解引用悬空指针。

* 修复client非正常退出导致UBRING shm残留的问题

client被强杀(SIGTERM/崩溃/OOM)时teardown没跑完,localShm(_C)的
shm_unlink未执行,导致/dev/shm残留_C文件。server的remoteShm只munmap
不unlink(正确),无法清理client的名字。

在握手ESTABLISHED时(client/server都确认对方已mmap自己的localShm)
立即unlink localShm名字。此时对端已持有mmap引用,unlink只删名字不
影响通信;进程任意时刻退出都不会残留文件名。

* Address chenBright's review: use English comments and BAIDU_CACHELINE_ALIGNMENT

- Convert all Chinese comments in ubshm to English (per chenBright's
  'Please use English' on ub_endpoint.cpp:723, ub_ring.cpp:337,
  shm_ubs.cpp:316, and similar)
- Replace __attribute__((aligned(64))) with BAIDU_CACHELINE_ALIGNMENT
  in ubr_msg.h (per chenBright's comment on ubr_msg.h:41)
- Remove unnecessary TODO comment in ub_ring.cpp:551 (per chenBright's
  'Unnecessary comments, please delete')

* Remove unused lock macros in thread_lock.h

Per chenBright's review, the functions and macros defined in
thread_lock.h are largely unused. Verified usage across ubshm:
- LOCK_GUARD / UnlockMutex: 8 call sites in shm_ubs.cpp and
  ub_ring_manager.cpp, kept.
- SPIN_LOCK_GUARD, R_LOCK_GUARD, W_LOCK_GUARD, SEMAPHORE_WAIT_GUARD,
  SEMAPHORE_WAIT_GUARD_WITH_CLOSE and their helper functions
  (UnlockSpinLock, UnlockRWLock, PostSem, PostSemWithClose): 0 call
  sites, removed.

* Apply chenBright's review on timer_mgr globals

Per chenBright's review on timer_mgr.cpp:32-37:
- Add explicit default values to uninitialized globals
  (g_total_timer_num=0, g_max_system_fd=0, g_epoll_execute_thread=0,
  g_timer_module_initialized=0)
- Rename globals to snake_case (g_epollFd -> g_epoll_fd,
  g_totalTimerNum -> g_total_timer_num, g_timerFdCtxMap ->
  g_timer_fd_ctx_map, maxSystemFd -> g_max_system_fd,
  g_epollExecuteThread -> g_epoll_execute_thread,
  g_timerModuleInitialized -> g_timer_module_initialized)
- maxSystemFd also gains the g_ prefix to match global naming style

Also fix the missing std:: qualifier on atomic_fetch_sub/add/load
(per chenBright's earlier comment on timer_mgr.cpp:80).

* Change CloseTimerFd fd type from uint32_t to int

Per chenBright's review on timer_mgr.cpp:399 (uint32_t -> int).
fd is a system file descriptor; POSIX APIs use int and -1 denotes an
invalid fd, which uint32_t cannot represent. Changed the CloseTimerFd
signature (header + definition) and removed the now-unnecessary
(uint32_t) casts at the two call sites.

* Use BAIDU_LIKELY/BAIDU_UNLIKELY instead of custom __builtin_expect

Per chenBright's review on common.h:27. Rather than redefine the
macros with __builtin_expect directly, forward LIKELY/UNLIKELY to
brpc's standard BAIDU_LIKELY/BAIDU_UNLIKELY (from butil/compiler_specific.h).
The 122 call sites keep using LIKELY()/UNLIKELY() unchanged; only the
macro bodies change, preserving semantics.

* Add unit tests for UBShmEndpoint

Per chenBright's request to add unit tests for UBShmTransport in this
PR (rather than a follow-up).

Adds test/brpc_ubring_unittest.cpp with tests covering the public
interface of UBShmEndpoint under the g_skip_ub_init=true mode (which
skips real shared-memory/poller setup):
- construct_and_destruct: lifecycle safety
- is_writable_false_when_skip_init: skip-mode behavior
- reset_is_idempotent: Reset() is safe to call repeatedly

The file follows the brpc_*_unittest.cpp naming convention so it is
auto-collected by test/CMakeLists.txt's file(GLOB). Verified: compiles,
links, and all 3 tests pass (g++ 15.2, C++17, gtest, BRPC_WITH_UBRING=ON).

* Rewrite UBShmEndpoint unit tests with real coverage

Per chenBright's feedback that the previous tests were too simple and
did not cover the main methods.

Source changes to enable testing:
- Move HelloMessage struct declaration from ub_endpoint.cpp to
  ub_endpoint.h so tests can access it
- Expose private members under #ifdef UNIT_TEST (precedent:
  butil/containers/stack_container.h) so tests can call
  AllocateClientResources without -Dprivate=public (which breaks
  GCC 15 + new libstdc++ <any>/<sstream>)

Tests (9, all passing on Ubuntu 26.04 g++ 15.2 C++17 gtest):
HelloMessageTest (5): serialize/deserialize roundtrip, network byte
order verification, uint64 max boundary, full shm_name, toString
UBShmEndpointTest (4): construct, real IPC shm
AllocateClientResources (g_skip_ub_init=false), reset cleanup, reset
idempotency

* rename the variable to snake_case style

---------

Co-authored-by: YeChang Guo <52730608+YChange01@users.noreply.github.com>
Co-authored-by: 郭业昌 <lvpengfei@MacBook-Air.local>
Co-authored-by: gure <740684863@qq.com>
2026-07-19 13:02:08 +08:00
chenBright e2172be6e5 Support end-to-end ECE negotiation in RDMA handshake V3
Previously BringUpQp only did a local ibv_query_ece + ibv_set_ece
roundtrip and never exchanged ECE capabilities with the peer.
This patch wires up the standard requestor/responder ECE negotiation
flow on top of the existing v3 handshake without adding any extra
round trip:

1. Client queries local ECE, advertises it in its v3 hello.

2. Server applies the client's ECE in INIT->RTR (set_ece), then
   after RTS queries the reduced/negotiated ECE and sends it back
   in the reply hello.

3. Client applies the server's reduced ECE in INIT->RTR.
2026-07-19 01:03:20 +08:00
Bright Chen 56445c5076 Support LeakSanitizer (#3361) 2026-06-28 14:04:39 +08:00
Aurélien Pupier b393fa2c9e Configure GitHub workflows to use concurrency cancel-in-progress for (#3333)
pull requests

see recommended best practices at Apache
https://cwiki.apache.org/confluence/pages/viewpage.action?spaceKey=INFRA&title=GitHub+Actions+Recommended+Practices

Signed-off-by: Aurélien Pupier <apupier@ibm.com>
2026-06-14 11:54:24 +08:00
Bright Chen 72adb6ec24 Support RDMA handshake V3 (#3326)
Background
==========
The legacy v2 handshake ("RDMA" magic + 36B fixed binary HelloMessage)
had correctness bugs that made the wire format effectively
unevolvable.

v2 bugs
=======
A. Client never drained the "unknown tail" bytes when a peer sent
   msg_len > HELLO_MSG_LEN_MIN(40). Leftover bytes stayed in the
   socket recv buffer and silently corrupted the next ReadFromFd
   (the ACK).
B. Server had the symmetric version of A.
C. Server computed the body read length from its LOCAL
   g_rdma_hello_msg_len, implicitly assuming the peer's hello is the
   same length as its own. A longer peer left bytes behind; a shorter
   peer made the read block. Client used the correct compile-time
   constant; the two sides were not symmetric.

Combined, A/B/C meant v2 could not safely append a single byte to the
hello -- even an "optional hint" appended by a newer sender would
mis-align an older receiver's next read.

v3 design
=========
Wire format, magic-namespace-isolated from v2:

  [ "RDM3" 4B ][ pb_size 4B big-endian ][ RdmaHello protobuf bytes ]

with pb_size in (0, 4096]. RdmaHello carries the same 6 base fields
as v2 plus room to append future capabilities.

Why protobuf (and not "v2 plus length prefix")
----------------------------------------------
- Variable-length fields are coming. Future capability fields will
  include strings (rdma_device_name, netdev_name, ...) and other
  variable-length data. Supporting them on a fixed-binary protocol
  forces us to invent and maintain a TLV layer (per-field type +
  length + value framing, plus version-aware deserialization). That
  is reimplementing protobuf badly. Using protobuf from day one
  costs nothing and is the canonical answer.
- Fixes v2 bug A/B/C generically: pb_size makes the wire
  self-describing, so the receiver never needs to guess the length
  or know the peer's schema version to read the body cleanly.
- Append-only field evolution out of the box: new optional fields
  cost old receivers nothing -- they're skipped as unknown protobuf
  fields. v2 with a hand-rolled length prefix would still need
  per-field opt-in code on every side.
- Built-in validation: ParseFromArray fails fast on malformed input;
  required-field presence is enforced at the parse layer, not by
  ad-hoc has_xxx() checks scattered through wire code.
- bRPC already depends on protobuf -- no new build dependency.

Why a NEW MAGIC rather than a version field inside protobuf
-----------------------------------------------------------
- Forces "breaking change" to be a deployment decision visible at
  the wire level. You cannot accidentally ship a backwards-
  incompatible patch via a field-semantics tweak.
- Server-side dispatch routes by magic to fully independent state
  machines that can't entangle (no `if (version == X)` branches
  anywhere -- this is the abstraction's red line).
- Any future breaking change bumps the magic ("RDM4", "RDM5", ...).
  v3 fields, once shipped, never change semantics.

Rollout
=======
Server-side ALWAYS accepts both v2 and v3 (no gflag, no kill-switch);
magic routes to fully independent code paths. A single rolling upgrade
enables v3 fleet-wide.

Client-side picks the wire protocol via gflag with a safe default:

    FLAGS_rdma_client_handshake_version  (default 2)
      2 = "RDMA" legacy (zero-regression default)
      3 = "RDM3" protobuf (opt-in once target servers support v3)

Sub-second rollback is one flag flip away. v3 client to v2-only legacy
server is NOT guaranteed to transparently fall back on the same
connection -- the supported migration is "upgrade servers first, then
opt-in clients".
2026-06-05 17:15:54 +08:00
rajvarun77 1d21b050b8 ci(linux): bring up redis-server and mysql-server for unittests (#3323)
* ci(linux): bring up redis-server and mysql-server for unittests

The clang-unittest and clang-unittest-asan jobs run the full unit test
suite via test/run_tests.sh, which includes backend integration tests
(e.g. brpc_redis_unittest) that fork a real server when its binary is
present and otherwise silently short-circuit to a passing result. Since
CI never installed those servers, the redis backend tests reported
PASSED while doing nothing (7 of 14 RedisTest cases skip-as-pass).

Install redis-server and mysql-server before running the tests in both
unittest jobs so these backend tests execute against a live server. The
binaries are added only in the unittest jobs, not in the shared
install-essential-dependencies action used by compile-only jobs.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* ci(linux): skip flaky redis client tests under ASan

brpc_redis_unittest forks a real redis-server and waits a fixed 50ms before
connecting; under ASan redis starts too slowly, causing flaky connection-refused.
Skip RedisTest.* in the ASan job only (still covered by clang-unittest).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* ci(linux): install redis-server and mysql-server in install-essential-dependencies

Move the redis-server/mysql-server install out of the individual
clang-unittest and clang-unittest-asan jobs and into the shared
install-essential-dependencies composite action, so every job that
installs dependencies has the servers available (and the unittest jobs
no longer carry a bespoke install step).

Under ASan the redis integration tests (sanity, keys_with_spaces,
incr_and_decr, by_components, auth) fork a real redis-server and connect
after a fixed 50ms wait; redis starts too slowly there and they flake
with connection refused. Filter just those out under ASan -- the redis
codec/server tests still run, and the full suite runs in clang-unittest.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* ci(linux): run forked-server integration tests under bazel

The bazel unittest jobs ran //test/... without redis-server/mysql-server
installed, so brpc_redis_unittest forked nothing and its integration cases
(sanity/keys_with_spaces/incr_and_decr/by_components/auth) early-returned as
passes -- green but vacuous.

- Install redis-server/mysql-server in the (non-ASan) bazel test jobs via the
  shared install-essential-dependencies action (the same one the make jobs
  use), so the servers are on PATH for the forked tests.
- Tag brpc_redis_unittest "external" + "local" so bazel always re-runs it
  (never serves a cached skip) and runs it outside the sandbox where the
  PATH-located redis-server is visible and loopback works. Threaded through
  generate_unittests via a new per_test_tags arg.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: rajvarun77 <287367605+rajvarun77@users.noreply.github.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-05 10:13:07 +08:00
Bright Chen cd3948ceac Refactor Bazel build with custom proto rules and build all test targets (#3313) 2026-05-31 10:48:30 +08:00
Bright Chen 486f07a3e3 Fix CI installation errors (#3233) 2026-03-01 12:26:47 +08:00
Bright Chen ede6b7763a Fix rdma UT (#3146) 2025-11-09 16:50:42 +08:00
Bright Chen 1d3bded92a Support higher performance bvar with babylon counter (#3116)
* Support higher performance bvar with babylon counter

* Update documents
2025-10-26 15:22:43 +08:00
fanbingxin 4eeb5e260a bazel: fix with_bthread_tracer config setting (#3111) 2025-10-08 17:13:01 +08:00
Bright Chen 1edc9a9465 Fix macos ci compatibility with CMake < 3.5 (#3093) 2025-09-15 19:52:05 +08:00
Bright Chen 5fe65d04c4 Fix macos ci (#3080) 2025-08-31 20:26:10 +08:00
Bright Chen bea48d75fe Bugfix: SignalTrace mode has memory and deadlock issues (#3019)
* Bugfix: SignalTrace mode has memory and deadlock issues

* Bugfix: Memory leak of SignalSync and wrong status of global priority bthread
2025-07-18 23:35:00 +08:00
Bright Chen decdf3e7d8 Fix compile errors of json2pb (#2956) 2025-04-24 10:15:49 +08:00
wwbmmm a4e5436ee9 Change issue and PR templates to encourage contributors to use English 2025-04-22 17:01:05 +08:00
Bright Chen f44f803a96 Fix asan switch fiber with error stack info (#2931)
* Fix __sanitizer_start_switch_fiber with error stack info

* Enable detect_stack_use_after_return in UT

* Fix reuse thread stack with asan
2025-04-02 20:27:41 +08:00
Bright Chen 7a7d1c83e5 Support AddressSanitizer (#2890)
* Support AddressSanitizer

* Add gperftools helper header
2025-03-26 20:07:45 +08:00
Bright Chen 3e97efee97 Update ubuntu-20.04 to ubuntu-22.04 in CI (#2909) 2025-03-05 21:48:00 +08:00
Bright Chen 71184b03f1 Support bthread tracer with bazel (#2905) 2025-03-04 21:49:40 +08:00
Bright Chen e45e957b0d Fix some compilation warning issues (#2876) 2025-01-16 11:05:33 +08:00
Bright Chen a18463f6c3 Support task tracer (#2851)
* Support task tracer

* Opt signal trace

* Rename BRPC_VALIDATE_GFLAG to BUTIL_VALIDATE_GFLAG

* Update picture of document
2025-01-06 14:43:55 +08:00
Weibing Wang bb527a1635 Upgrade upload-artifact version (#2827) 2024-11-26 14:19:45 +08:00
Bright Chen f4e00acc30 Support detection of mutex deadlock caused by double lock (#2765)
* Support detection of bthread mutex and FastMutex deadlock caused by double lock

* Support detection of pthread mutex deadlock caused by double lock
2024-10-13 20:37:53 +08:00
Bright Chen 9680d31edb Support timedlock of fast/hook pthread and bthread::Mutex (#2760)
* Support timedlock of fast/hook pthread and bthread::Mutex

* Disable bthread sche safety debug by default
2024-10-09 12:36:00 +08:00
Jenrry You 7e5ec4fe8d Batch create and accept stream (#2754)
* feat: batch create and accept stream

* fix protobuf 22.5 compilation error related to thread_local in MacOS

* refine style

* modify code based on the code review feedback and add more tests

modify code based on the code review feedback  and add more tests
2024-10-09 10:39:42 +08:00
Bright Chen 658ac6b77a Fix link of CODE_OF_CONDUCT.md in pull request template (#2735) 2024-08-12 13:54:20 +08:00
Bright Chen 7a89de7f33 Fix rdma complie error (#2707)
* Fix rdma complie error

* Fix ut bins
2024-07-25 11:10:18 +08:00
Kevin Li 9d23af8e92 add bzlmod support (#2670)
* add bzlmod support

* drop buggy clang-11 which dont suport -fno-access-control correctly

* fix typo in ci-linux.yml

* give up trying to test bazel in clang
2024-07-14 18:11:28 +02:00
Bright Chen 6a335aa8bc Fix ci (#2611) 2024-04-23 17:15:16 +08:00
Xiaofeng Wang d7eca3991f ci: fixed protobuf and abseil versions (#2596)
* ci: fixed protobuf and abseil versions

* ci: ignore dependencies
2024-04-09 21:02:37 +08:00
Bright Chen ca92daabee Install gdb for linux ci (#2587) 2024-04-01 10:46:46 +08:00
Xiaofeng Wang 37814d2da8 Support Protobuf 22 (#2546)
* Support Protobuf 22

* config_brpc.sh: support to build with protobuf 22

* ci-macos: compatible with Apple silicon

* ci: compile with protobuf 22+ using macos
2024-03-13 13:31:41 +08:00
Arjun Singh fa9788558b [Fuzzing] add cifuzz (#2521)
Signed-off-by: Arjun Singh <ajsinghyadav00@gmail.com>
2024-02-04 17:18:06 +01:00
Dongsheng He 761b399e50 Support compile with boringssl (#2399)
* support boringssl

* add CMakeLists

* fix

* suopport boring ssl bazel

* fix AddBioBuffer code

* fix compile

* add boringssl compile bazel ci

* set compile with boringssl as a dependent job

---------

Co-authored-by: Dongsheng He <hds@dipeak.com>
2023-10-25 15:04:53 +08:00
Weibing Wang 937783ba9a Fix macos ci failed with protobuf version (#2287) 2023-06-25 17:06:31 +08:00
Nancy Ngo 1bd072e5de Update github workflows to skip builds for markdown-file-only changes (#2175) 2023-03-23 12:21:45 +08:00
果冻虾仁 8c2e8c15a4 修复CI流水线编译失败的问题 2023-02-21 15:23:46 +08:00
果冻虾仁 988fcd012b 20.04 (#2030) 2022-12-02 10:11:28 +08:00
果冻虾仁 9cdced4fb5 Add Action Badge and Remove Travis file (#2023) 2022-11-28 13:17:51 +01:00
果冻虾仁 1936db9ce2 Support all compile options and unittest for Linux workflow (#2018)
Support all compile options and unittest for Linux workflow #2018
2022-11-27 20:03:48 +01:00
果冻虾仁 93a49cd826 Support Clang compile for Linux workflow (#2015)
* clang

* mergefile

* bazel
2022-11-25 09:36:25 +08:00
果冻虾仁 d8b21d7c90 Linux workflow (#2008)
Support compile-with-make, compile-with-cmake, compile-with-bazel for Linux in Github Actions
2022-11-23 20:37:23 +01:00
Jiashun Zhu 96c690a0d7 Merge pull request #1899 from guodongxiaren/master
Add github action for MacOS CI
2022-10-30 22:48:32 +01:00
serverglen b97ee82c4a Update pull_request_template.md (#1970) 2022-10-28 10:05:14 +08:00
果冻虾仁 4bb99f16e7 delete test 2022-10-27 23:23:16 +08:00