Commit Graph

3688 Commits

Author SHA1 Message Date
Weibing Wang b94b1c8777 Revert "Progressive timeout dev (#3409)"
This reverts commit e0abb1001e.
2026-08-16 17:30:20 +08:00
Xiaofeng Wang 9aa41f79f2 Support flow-controlled gRPC client requests (#3430)
* Support flow-controlled gRPC client requests

- Split client request DATA frames according to the peer's connection and
  stream flow-control windows.
- Buffer unsent DATA and resume transmission when WINDOW_UPDATE restores
  capacity.
- Track pending request bytes per H2 connection and apply
  socket_max_unwritten_bytes as an upper bound.
- Reject or reroute new requests once the pending DATA limit is reached.
- Release buffered DATA when an RPC fails, times out, or its stream is
  removed.
- Add tests for fragmented transmission, deferred DATA flushing,
  pending-byte accounting, and buffer cleanup.

* Fix pending HTTP/2 data limit race

- Check pending DATA capacity atomically with client stream insertion.
- Leave stream and window state unchanged when the limit is exceeded.
- Use an ephemeral port in the gRPC flow-control test.
- Avoid accessing an empty payload buffer in H2 frame tests.
2026-08-16 15:22:43 +08:00
Bright Chen 48db968fa0 Refactor NULL with nullptr in butil (#3444) 2026-08-16 10:29:58 +08:00
Weibing Wang 552bfd6e25 Fix SOFA PBRPC parser not limiting metadata size (#3449)
ParseSofaMessage only checked body_size against max_body_size, while
meta_size and the total frame size were left unbounded. A frame with a
large meta_size and zero body_size passed the body_size check and made
the connection keep buffering far beyond the configured limit before the
invalid metadata was rejected. Bound meta_size by max_body_size as well,
consistent with other protocols such as baidu_std and hulu_pbrpc.

Add unit tests covering oversized body and oversized metadata.
2026-08-16 01:08:59 +08:00
Weibing Wang ca370c28a9 Fix RTMP abort message deleting the chunk stream being parsed (#3452)
* Fix RTMP abort message deleting the chunk stream being parsed

* Address review comments on RTMP abort regression test
2026-08-16 01:08:30 +08:00
Weibing Wang 437a7b705c Limit mcpack2pb array item count to the actual payload size (#3451)
* Limit mcpack2pb array item count to the actual payload size

The item count in an mcpack array header is read directly from the
request and was used as-is by the generated parsing code to Reserve()
memory for repeated protobuf fields. A malformed request could claim an
item count up to INT32_MAX and force the server to preallocate ~16GB of
virtual memory, which may abort the process on memory-constrained hosts.

Cap the item count by the remaining bytes of the array (each item
occupies at least one byte) so that the preallocation is bounded by the
request size.

* Fix underflow in mcpack2pb array item count clamping
2026-08-16 01:06:46 +08:00
Chuang Zhang e0abb1001e Progressive timeout dev (#3409)
* add the progressive timeout reader

* optimize the code format

* WIP: progressive read timeout review

* test: strengthen progressive read timeout coverage
2026-08-15 16:56:56 +08:00
UB 24146ca556 cap simple string length in RedisReply::ConsumePartialIOBuf (#3404)
* cap simple string length in RedisReply::ConsumePartialIOBuf

Signed-off-by: ubeddulla khan <ubed@bugqore.com>

* reject negative redis_max_allocation_size in simple string branch

Signed-off-by: ubeddulla khan <ubed@bugqore.com>

* enforce redis simple string cap while waiting for CRLF

Signed-off-by: ubeddulla khan <ubed@bugqore.com>

---------

Signed-off-by: ubeddulla khan <ubed@bugqore.com>
2026-08-15 14:12:00 +08:00
Bright Chen 3124cf035d Replace NULL with nullptr in butil/containers (#3437) 2026-08-15 13:57:09 +08:00
Bright Chen a2a43d951a Refactor NULL with nullptr in butil/threading (#3443) 2026-08-15 13:56:50 +08:00
Bright Chen 9f9b62f683 Refactor NULL with nullptr in butil/strings (#3442) 2026-08-15 13:56:33 +08:00
Bright Chen a22d3052c8 Refactor NULL with nullptr in butil/memory (#3441) 2026-08-15 13:56:15 +08:00
Bright Chen 950cf26f9b Refactor NULL with nullptr in butil/files (#3440) 2026-08-15 13:55:57 +08:00
Bright Chen bd6fa80ba6 Replace NULL with nullptr in butil/details, butil/mac, butil/synchronization and butil/time (#3439) 2026-08-15 13:55:40 +08:00
Bright Chen 5a80007eb1 Replace NULL with nullptr in butil/debug (#3438) 2026-08-15 13:55:23 +08:00
Chuang Zhang 04d0bf0f80 fix(test): avoid overriding the configured C++ standard (#3446) 2026-08-15 11:08:02 +08:00
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
Regal 117531111d test: wait for submitted spans to be collected (#3448)
Wait for the asynchronous span collector to release root client spans
after Controller reset or submission. This prevents LeakSanitizer from
reporting pending test spans when the short-lived test binary exits
before the collector’s first polling interval.

Signed-off-by: Zhengwei Zhu <141622927+ZhengweiZhu@users.noreply.github.com>
2026-08-15 09:42:04 +08:00
Bright Chen febb014aaa Signal workers for priority tasks (#3423) 2026-08-10 10:20:11 +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
lh2debug-2 cb84e83c59 fix rpcz root client span lifetime (#3420) (#3421)
Keep the current RPC span alive from Controller until the RPC finishes,
SubmitSpan runs, or the Controller is reset. This lets root client spans
without a local parent be submitted to rpcz instead of being destroyed
after the caller-side temporary shared_ptr goes out of scope.

Child client spans remain linked to their parent through weak local-parent
references and parent-owned client lists, so they are still serialized
under their parent without introducing shared_ptr cycles.

Co-authored-by: lh2debug <lh2debug@163.com>
2026-08-09 15:03:54 +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
Bright Chen 0ec3a9ddaa Refactor streaming rpc (#3422) 2026-08-09 14:35:44 +08:00
Bright Chen 0c8aede171 Fix rdma handshake failing the socket instead of falling back to TCP (#3424) 2026-08-07 17:38:10 +08:00
Bright Chen 159c85505c Fix RDMA PollCq missing recv CQEs after re-arming the CQs (#3425)
PollCq only re-polled send_cq after arming both CQs, so a recv CQE
arriving in the one-shot notification race window of recv_cq was left
in the CQ and the RPC timed out. Restart the re-poll from recv_cq so
that both CQs are covered.
2026-08-07 17:38:00 +08:00
darion-yaphet 0313102276 build(cxx): align all builds on a C++14 baseline (#3419)
* build(cxx): align all builds on a C++14 baseline

CMake, Make, tests, tools, and examples now require C++14 so every supported build path shares the same minimum language level. The compiler checks and user-facing documentation reflect that baseline.

* fix(test): keep cores scoped to the failing test

Clear prior cores before each test binary. A passing death test can leave a core that would otherwise be used to diagnose an unrelated later failure.

* revert src/butil/type_traits.h
2026-08-06 17:34:49 +08:00
dwh110 956227b077 cputime optimize for arm64 (#3247)
* cputime optimize for arm64
Update src/butil/time.cpp
modify  using __attribute__((constructor)) and merge init_invariant_cpu_freq to inside function read_invariant_cpu_frequency

* Add the macro switch BUTIL_USE_CPU_FREQUENCY while preserving the original default behavior for ARM64

* 1、Activation options: CMake -DWITH_CPU_FREQUENCY=ON, Bazel --define BUTIL_USE_CPU_FREQUENCY=true, script argument --with-cpu-frequency.
2、Disabled by default for consistent legacy behavior.

* fix compile failed

---------

Co-authored-by: seekdwh <dongweihao@huawei.com>
2026-08-06 14:09:21 +08:00
LorinLee c2f39eba8a Merge pull request #3408 from wwbmmm/verify-tls-peer-name
Add TLS peer name verification for clients
2026-07-31 09:44:16 +08:00
wwbmmm ef7e5b9ce2 Keep compatible with MesaLink and old version OpenSSL 2026-07-30 14:10:05 +08:00
UB b52299c4f2 guard underflowed value size in couchbase collection responses (#3402)
* guard underflowed value size in couchbase collection responses

* Compute couchbase value_size as int64_t to avoid int overflow
2026-07-30 13:58:58 +08:00
Yang,Liming c9ab283ca4 Merge pull request #3407 from yanglimingcn/feat/attachment_with_checksum
Build and Test on Linux / compile-with-make (push) Has been cancelled
Build and Test on Linux / compile-with-cmake (push) Has been cancelled
Build and Test on Linux / gcc-compile-with-make-protobuf (push) Has been cancelled
Build and Test on Linux / gcc-unittest-with-bazel (push) Has been cancelled
Build and Test on Linux / gcc-compile-with-bazel-all-options (push) Has been cancelled
Build and Test on Linux / clang-compile-with-make-protobuf (push) Has been cancelled
Build and Test on Linux / clang-unittest-with-bazel (push) Has been cancelled
Build and Test on Linux / clang-compile-with-bazel-all-options (push) Has been cancelled
Build and Test on Linux / clang-unittest (push) Has been cancelled
Build and Test on Linux / clang-unittest-asan (push) Has been cancelled
Build and Test on Linux / clang-unittest-bazel-with-babylon-and-new-pb (push) Has been cancelled
Build on Macos / compile-with-make-cmake-protobuf21 (push) Has been cancelled
Build on Macos / compile-with-make-cmake-protobuf29 (push) Has been cancelled
Build on Macos / compile-with-bazel (push) Has been cancelled
License Check / License Check (push) Has been cancelled
Support checksumming the attachment together with the body
2026-07-28 14:45:15 +08:00
Lijin Xiong 5f228c0304 Fix race when falling back from RDMA to TCP (#3406)
Make the handshake state atomic and publish RDMA_OFF before
FALLBACK_TCP. This prevents TCP event handling from observing a
partially published fallback state. Use a relaxed load for the
completion-path check because it does not consume related data.

Signed-off-by: Lijin Xiong <legion.xiong@gmail.com>
Co-authored-by: Lijin Xiong <lijin.xiong@zstack.io>
2026-07-27 08:49:40 +02:00
Yang Liming 11b7d80049 Support checksumming the attachment together with the body
Controller::set_request/response_checksum_type() previously only
covered the serialized protobuf body; the attachment (if any) was
never protected. Add set_request/response_checksum_attachment(bool)
so callers can opt the attachment into the same checksum.

- baidu_rpc_meta.proto: add RpcMeta.checksum_with_attachment so the
  receiver knows whether to fold the attachment into verification.
  Defaults to false, so old peers that don't understand the field
  keep verifying against the body only (backward compatible).
- Controller: add the two setters/getters, thread the flag through
  ClientSettings (Save/ApplyClientSettings) so ParallelChannel/
  SelectiveChannel sub-controllers inherit it correctly, and reset it
  in ResetPods().
- ChecksumIn: add an optional `attachment' field consumed by checksum
  handlers.
- crc32c_checksum.cpp: extend the crc32c over body then attachment (in
  that fixed order) when requested.
- baidu_rpc_protocol.cpp: wire checksum_attachment through
  SerializeRpcMessage/DeserializeRpcMessage and every client/server
  send/receive path; skip it when progressive attachment reading is
  enabled since there's no single complete IOBuf to checksum in that
  case.

Add brpc_checksum_unittest.cpp covering Crc32cCompute/Crc32cVerify
directly (including corruption/omission/order sensitivity) and an
end-to-end Server/Channel test for both request- and response-side
attachment checksums.
2026-07-27 11:01:39 +08:00
UB 7c1b522539 Fix use-after-free of the new block in SingleIOBuf::assign (#3397)
Build and Test on Linux / compile-with-make (push) Has been cancelled
Build and Test on Linux / compile-with-cmake (push) Has been cancelled
Build and Test on Linux / gcc-compile-with-make-protobuf (push) Has been cancelled
Build and Test on Linux / gcc-unittest-with-bazel (push) Has been cancelled
Build and Test on Linux / gcc-compile-with-bazel-all-options (push) Has been cancelled
Build and Test on Linux / clang-compile-with-make-protobuf (push) Has been cancelled
Build and Test on Linux / clang-unittest-with-bazel (push) Has been cancelled
Build and Test on Linux / clang-compile-with-bazel-all-options (push) Has been cancelled
Build and Test on Linux / clang-unittest (push) Has been cancelled
Build and Test on Linux / clang-unittest-asan (push) Has been cancelled
Build and Test on Linux / clang-unittest-bazel-with-babylon-and-new-pb (push) Has been cancelled
Build on Macos / compile-with-make-cmake-protobuf21 (push) Has been cancelled
Build on Macos / compile-with-make-cmake-protobuf29 (push) Has been cancelled
Build on Macos / compile-with-bazel (push) Has been cancelled
License Check / License Check (push) Has been cancelled
Signed-off-by: ubeddulla khan <ubed@bugqore.com>
2026-07-26 17:56:42 +08:00
wwbmmm 436571e725 Add TLS peer name verification for clients 2026-07-26 11:43:47 +08:00
darion-yaphet e044428713 refactor(bvar): replace NULL with nullptr (#3403)
Build and Test on Linux / clang-unittest (push) Has been cancelled
Build and Test on Linux / compile-with-make (push) Has been cancelled
Build and Test on Linux / compile-with-cmake (push) Has been cancelled
Build and Test on Linux / gcc-compile-with-make-protobuf (push) Has been cancelled
Build and Test on Linux / gcc-unittest-with-bazel (push) Has been cancelled
Build and Test on Linux / gcc-compile-with-bazel-all-options (push) Has been cancelled
Build and Test on Linux / clang-compile-with-make-protobuf (push) Has been cancelled
Build and Test on Linux / clang-unittest-with-bazel (push) Has been cancelled
Build and Test on Linux / clang-compile-with-bazel-all-options (push) Has been cancelled
Build and Test on Linux / clang-unittest-asan (push) Has been cancelled
Build and Test on Linux / clang-unittest-bazel-with-babylon-and-new-pb (push) Has been cancelled
Build on Macos / compile-with-make-cmake-protobuf21 (push) Has been cancelled
Build on Macos / compile-with-make-cmake-protobuf29 (push) Has been cancelled
Build on Macos / compile-with-bazel (push) Has been cancelled
License Check / License Check (push) Has been cancelled
Modernize pointer null literals across bvar sources for C++11
consistency, including pthread APIs and related comments.
2026-07-22 23:41:08 +08:00
Felix-Gong 5197621b91 Optimize StringPiece memcmp/memchr for RISC-V with RVV (#3396)
This patch adds RVV-accelerated memcmp and memchr for StringPiece operations
on RISC-V 64-bit platforms.

The implementation follows glibc's official RVV memcmp/memchr patterns:
- e8m8 LMUL for maximum throughput
- Hardware-adaptive vector length via vsetvl
- vfirst.m for early-out on first difference/match

Performance on SOPHGO SG2044 (RVV 1.0, VLEN >= 128, GCC 15.1):
glibc 2.38 scalar memcmp (no RVV acceleration) as baseline.

  memcmp (worst-case full scan, 50000 iterations):
    64 B:   20 ns ->   6 ns  (3.4x)
   256 B:   54 ns ->  15 ns  (3.6x)
     1 KB: 120 ns ->  55 ns  (2.2x)
     4 KB: 435 ns -> 225 ns  (1.9x)
    16 KB: 1968 ns -> 1258 ns (1.6x)
    64 KB: 10962 ns -> 9044 ns (1.2x)
   256 KB: 46893 ns -> 43108 ns (1.1x)
     1 MB: 446161 ns -> 454717 ns (1.01x)

  memchr (worst-case full scan, 50000 iterations):
    64 B:    5 ns ->  0.9 ns  (5.8x)
   256 B:   12 ns ->   3 ns  (4.0x)
     1 KB:   40 ns ->  12 ns  (3.3x)
     4 KB:  148 ns ->  44 ns  (3.4x)
    16 KB:  558 ns -> 158 ns  (3.5x)
    64 KB: 2150 ns ->  635 ns (3.4x)
   256 KB: 9200 ns -> 2900 ns (3.2x)
     1 MB: 39000 ns -> 13000 ns (3.0x)

Correctness:
  - 59/59 expanded correctness tests passed (64B - 1MB)
  - string_piece_unittest: 24/24 passed
  - test_butil: 724/725 passed (1 pre-existing StackTrace failure)
  - test_bvar: 64/64 passed

Files changed:
  - src/butil/string_compare_rvv.cc (new): RVV memcmp + memchr implementations
  - src/butil/strings/string_piece.h: RVV dispatch declarations
  - src/butil/strings/string_piece.cc: RVV dispatch in find(char) for memchr
  - BUILD.bazel: added string_compare_rvv.cc to BUTIL_SRCS
  - CMakeLists.txt: added string_compare_rvv.cc
  - Makefile: added string_compare_rvv.cc

Signed-off-by: Xiaofei Gong <gongxiaofei24@iscas.ac.cn>
Signed-off-by: YuanSheng <yuansheng@isrc.iscas.ac.cn>
2026-07-22 17:00:33 +08:00
Felix-Gong d026d69be0 Optimize StringPiece memcmp for RISC-V with RVV (#3390)
* optimize StringPiece memcmp for RISC-V with RVV

This patch adds RVV-accelerated memcmp for StringPiece operations
on RISC-V 64-bit platforms.

The implementation follows glibc's official RVV pattern:
- e8m8 LMUL for maximum throughput
- Hardware-adaptive vector length via vsetvl
- vfirst.m for early-out on first difference

Performance on SOPHGO SG2044 (RVV 1.0, VLEN >= 128, GCC 15.1):
glibc 2.38 scalar memcmp (no RVV acceleration) as baseline.

  memcmp (worst-case full scan, 50000 iterations):
    64 B:   20 ns ->   6 ns  (3.4x)
   256 B:   54 ns ->  15 ns  (3.6x)
     1 KB: 120 ns ->  55 ns  (2.2x)
     4 KB: 435 ns -> 225 ns  (1.9x)
    16 KB: 1968 ns -> 1258 ns (1.6x)
    64 KB: 10962 ns -> 9044 ns (1.2x)
   256 KB: 46893 ns -> 43108 ns (1.1x)
     1 MB: 446161 ns -> 454717 ns (1.01x)

Correctness:
  - 59/59 expanded correctness tests passed (64B - 1MB)
  - string_piece_unittest: 24/24 passed
  - test_butil: 724/725 passed (1 pre-existing StackTrace failure)
  - test_bvar: 64/64 passed

Files changed:
  - src/butil/string_compare_rvv.cc (new): RVV memcmp implementation
  - src/butil/strings/string_piece.h: RVV dispatch in wordmemcmp (N >= 16)
  - BUILD.bazel: added string_compare_rvv.cc to BUTIL_SRCS
  - CMakeLists.txt: added string_compare_rvv.cc

Signed-off-by: Xiaofei Gong <gongxiaofei24@iscas.ac.cn>
Signed-off-by: YuanSheng <yuansheng@isrc.iscas.ac.cn>

* optimize StringPiece memcmp for RISC-V with RVV

This patch adds RVV-accelerated memcmp for StringPiece operations
on RISC-V 64-bit platforms.

The implementation follows glibc's official RVV pattern:
- e8m8 LMUL for maximum throughput
- Hardware-adaptive vector length via vsetvl
- vfirst.m for early-out on first difference

Performance on SOPHGO SG2044 (RVV 1.0, VLEN >= 128, GCC 15.1):
glibc 2.38 scalar memcmp (no RVV acceleration) as baseline.

  memcmp (worst-case full scan, 50000 iterations):
    64 B:   20 ns ->   6 ns  (3.4x)
   256 B:   54 ns ->  15 ns  (3.6x)
     1 KB: 120 ns ->  55 ns  (2.2x)
     4 KB: 435 ns -> 225 ns  (1.9x)
    16 KB: 1968 ns -> 1258 ns (1.6x)
    64 KB: 10962 ns -> 9044 ns (1.2x)
   256 KB: 46893 ns -> 43108 ns (1.1x)
     1 MB: 446161 ns -> 454717 ns (1.01x)

Correctness:
  - 59/59 expanded correctness tests passed (64B - 1MB)
  - string_piece_unittest: 24/24 passed
  - test_butil: 724/725 passed (1 pre-existing StackTrace failure)
  - test_bvar: 64/64 passed

Files changed:
  - src/butil/string_compare_rvv.cc (new): RVV memcmp implementation
  - src/butil/strings/string_piece.h: RVV dispatch in wordmemcmp (N >= 16)
  - BUILD.bazel: added string_compare_rvv.cc to BUTIL_SRCS
  - CMakeLists.txt: added string_compare_rvv.cc

Signed-off-by: Xiaofei Gong <gongxiaofei24@iscas.ac.cn>
Signed-off-by: YuanSheng <yuansheng@isrc.iscas.ac.cn>

* add string_compare_rvv.cc to Makefile BUTIL_SOURCES

---------

Signed-off-by: Xiaofei Gong <gongxiaofei24@iscas.ac.cn>
Signed-off-by: YuanSheng <yuansheng@isrc.iscas.ac.cn>
2026-07-22 11:19:10 +08:00
UB f818ebc05b Guard negative value_size in memcache PopStore (#3392)
* guard negative value_size in memcache PopStore

Signed-off-by: ubeddulla khan <ubed@bugqore.com>

* memcache: drop only the declared message when value_size is negative

Move the value_size < 0 check ahead of the pop_front so a malformed
reply no longer pops sizeof(header) + extras_length + key_length past
the declared message boundary. Discard exactly
sizeof(header) + total_body_length instead, keeping the following
pipelined responses aligned.

Signed-off-by: ubeddulla khan <ubed@bugqore.com>

---------

Signed-off-by: ubeddulla khan <ubed@bugqore.com>
2026-07-22 11:15:03 +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
UB a80df6fa2a Read GOAWAY fields before additional debug data (#3395)
Signed-off-by: ubeddulla khan <ubed@bugqore.com>
2026-07-21 10:32:01 +08:00
darion-yaphet f094566f54 build(example): extract shared CMake dependency helper for examples (#3391)
Example CMakeLists duplicated the same dependency discovery and link
setup. Move that into brpc_example_find_common_deps in
BrpcExample.cmake, migrate MySQL and other examples to use it, and
implement the helper as a macro so CMAKE_PREFIX_PATH, include paths,
and DYNAMIC_LIB propagate to the caller scope.
Example-specific deps stay local (e.g. readline/ncurses/thriftnb for
MySQL, gperftools for redis/http). LINK_SO behavior is unchanged.
2026-07-21 09:26:06 +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 881077d15b Support RDMA handshake protocol (#3350)
* Support RDMA handshake protocol

* Fix comment
2026-07-18 17:42:52 +08:00
sunhao 853fa6bede fix: set socket buffer options before connect (#3368) 2026-07-18 16:50:30 +08:00
Yang,Liming 92a0aba316 Merge pull request #3394 from altman08/dev
bthread: convert ADD/SUB_TLS_PTHREAD_LOCK_COUNT macros to inline function
2026-07-18 12:59:13 +08:00
altman08 af2d3e1586 bthread: convert ADD/SUB_TLS_PTHREAD_LOCK_COUNT macros to inline functions
Replace the function-like macros ADD_TLS_PTHREAD_LOCK_COUNT and
SUB_TLS_PTHREAD_LOCK_COUNT with inline functions
AddTlsPthreadLockCount() and SubTlsPthreadLockCount() (with matching
no-op definitions in the BRPC_DEBUG_BTHREAD_SCHE_SAFETY=0 branch).
Macros lack type safety and scoping, so encapsulating the logic in
regular functions is clearer and safer while keeping the same
behavior. All call sites are updated accordingly.
2026-07-17 19:40:01 +08:00
Yang,Liming e5ff754b31 Merge pull request #3393 from altman08/dev
bthread: use BAIDU_GET_VOLATILE_THREAD_LOCAL to access tls_unique_use…
2026-07-17 19:26:32 +08:00
altman08 ef64bc1e0a bthread: use BAIDU_GET_VOLATILE_THREAD_LOCAL to access tls_unique_user_ptr in sched_to
tls_unique_user_ptr was read directly without going through the
BAIDU_GET_VOLATILE_THREAD_LOCAL macro in TaskGroup::sched_to, while
the paired write later in the same function correctly used
BAIDU_SET_VOLATILE_THREAD_LOCAL. sched_to contains jump_stack, a
suspend-point where GCC (aarch64) and Clang may incorrectly cache
the address of a thread_local variable, which is exactly the hazard
BAIDU_GET_VOLATILE_THREAD_LOCAL is designed to avoid. Fix the read to
use the macro for consistency and correctness.
2026-07-17 18:45:26 +08:00