feat: limit Redis connections and fix GCC 13 test build - #29
Merged
Conversation
thweetkomputer
force-pushed
the
fix/baidu-thread-local-cstdint
branch
from
August 28, 2026 04:35
eccbe13 to
c8de3fb
Compare
thweetkomputer
marked this pull request as ready for review
August 28, 2026 04:40
This was referenced Aug 28, 2026
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What problem does this PR solve?
Issue Number: N/A
Problem Summary:
RedisServicehas no server-side connection limit. Request concurrency limits run after protocol parsing, so idle clients can exhaust connection resources, and excess TLS clients can enter an expensive handshake before the application rejects them.test/baidu_thread_local_unittest.cppusesuintptr_twithout directly including<cstdint>, which fails to compile with GCC 13.What is changed and the side effects?
Changed:
<cstdint>to the thread-local unit test.ServerOptions.redis_max_connections;0preserves unlimited admission.Server::SetRedisMaxConnections(size_t)so a running Redis-only listener can atomically enable, disable, raise, or lower the limit.accept, before creating a brpcSocket, so idle clients count and concurrent accepts cannot exceed the limit.redis_serviceset,enabled_protocols="redis", builtin services disabled, and no RPC or other protocol services on thatServer.-ERR max number of clients reachedto excess plaintext clients. When SSL is configured, close the accepted fd before creating a brpcSocketor starting TLS authentication.Serverinstances unaffected, and expose cumulative rejections throughServerStatistics.rejected_redis_connection_count.Side effects:
Performance effects(性能影响): Each accepted connection performs relaxed atomic connection accounting and loads the current atomic limit; limited Redis listeners use a relaxed CAS for admission. Runtime updates are one relaxed atomic store. There is no request hot-path cost.
Breaking backward compatibility(向后兼容性): Default runtime behavior remains unlimited. Adding fields changes the in-memory layouts of
ServerOptionsandServerStatistics, so consumers must rebuild their application and brpc library together.Check List:
eloqdata/brpcmasterleaves only the two requested changes and their tests/docs.test_butilandbrpc_server_unittestwith--parallel 4.BaiduThreadLocalTest.*passes (4 tests).ServerTest.close_idle_connectionspasses.IO_URING_ENABLED=ONbuildsbrpc_server_unittestwith--parallel 4.git diff --check origin/master...HEADpasses.Reviewer focus:
accept, release onSocket::Createfailure orBeforeRecycle, and update/read the runtime limit with relaxed ordering because the atomics publish no socket state.Rollback:
Set
redis_max_connectionsto0to retain unlimited admission, or revert the Redis-limit commit. The<cstdint>change is independent and test-only.