wwbmmm opened a new pull request, #3723: URL: https://github.com/apache/brpc/pull/3723
### What problem does this PR solve? Issue Number: resolve Problem Summary: `ProcessNsheadRequest()` wraps `MethodStatus::OnRequested()` in `CHECK()`, treating a rejection of the concurrency limiter as an impossible state. Both built-in limiters (`ConstantConcurrencyLimiter`, `AutoConcurrencyLimiter`) really return false under overload, so the first request that reaches the limit configured by the operator trips the check: with `-crash_on_fatal_log=true` the process aborts, and with the default configuration a FATAL log with a stack trace is emitted while the rejected request is served anyway, i.e. the configured limit is silently disabled and the logs are flooded at the request rate. Sibling protocols (thrift, baidu_std, http, mongo) fail the controller with ELIMIT instead. The same rejection was also discarded in `NsheadPbServiceAdaptor`, so the method-level limit was never enforced for nshead-based pb protocols. ### What is changed and the side effects? Changed: - `src/brpc/policy/nshead_protocol.cpp`: the service-level `MethodStatus::OnRequested()` result is checked inside the existing `do/while` validation block and a rejection fails the controller with `ELIMIT`, the same way as the other checks of that block, so the user handler (or the pb adaptor) answers the client instead of the request being served. The concurrency accounting stays balanced: `OnRequested()` counts the request even when it is rejected, and `ConcurrencyRemover` in `NsheadClosure::Run()` counts it out. - `src/brpc/nshead_pb_service_adaptor.cpp`: the method-level `OnRequested()` result is no longer ignored, an over-limit request fails with `ELIMIT` (`pbdone->status` is set before the check, so `OnResponded()` is still called on the failure path). - `test/brpc_server_unittest.cpp`: two regression tests, one for a plain `NsheadService` and one for a pb service served through `PublicPbrpcServiceAdaptor`. Each test holds the only concurrency slot with one request and verifies that the second request is rejected with `ELIMIT` and that the slot is recycled afterwards, so later requests are served again. Side effects: - Performance effects: none, the check is called at the same place with the same cost. - Breaking backward compatibility: none at the API level. Requests that reach a configured concurrency limit on nshead services are now answered with `ELIMIT` instead of being served (with a FATAL log, or aborting the process when `-crash_on_fatal_log=true`), which is the documented behavior of `max_concurrency` / `method_max_concurrency`. Tests run: - `brpc_server_unittest` (all 50 cases) - `brpc_public_pbrpc_protocol_unittest`, `brpc_nova_pbrpc_protocol_unittest`, `brpc_nshead_mcpack_protocol_unittest`, `brpc_interceptor_unittest` - `brpc_channel_unittest` (2 pre-existing failures unrelated to this change: `ChannelTest.parse_hostname` needs network access to www.baidu.com, `ChannelTest.backuprequest_selective_response_race` is flaky) --- ### Check List: - Please make sure your changes are compilable. - When providing us with a new feature, it is best to add related tests. - Please follow [Contributor Covenant Code of Conduct](https://github.com/apache/brpc/blob/master/CODE_OF_CONDUCT.md). --- 🤖 This PR was automatically created by brpc-oncall -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
