You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "lizining1231 (via GitHub)" <gi...@apache.org> on 2026/08/18 08:12:25 UTC

[PR] fix(benchmark): drain in-flight requests before canceling ctx in engine.Stop() [dubbo-go]

lizining1231 opened a new pull request, #3677:
URL: https://github.com/apache/dubbo-go/pull/3677

   ### Description
   Fixes #3675
   
   `engine.Stop()` cancels the parent context before draining in-flight requests, causing up to `concurrency` requests to be recorded as `context canceled` failures on every benchmark teardown. In low-QPS scenarios (1MiB payload), the failure rate reaches 0.86%, making the success-rate metric inaccurate.
   
   Swap `e.cancel()` and `e.wg.Wait()` so that in-flight requests complete naturally before the context is canceled. The `benchmarkFunc(ctx)` already has a `requestTimeout` safety bound
   
   ### Changes
   
   - `tools/benchmark/client/engine/engine.go` — swap `e.cancel()` and `e.wg.Wait()` in `Stop()`
   
   ### Test
   
   | Test | Description |
   | --- | --- |
   | 1MiB payload, 50 concurrency, 10s benchmark (before fix) | Failure <=50, logs flooded with `lastErr=canceled: context canceled` |
   | 1MiB payload, 50 concurrency, 10s benchmark (after fix) | Failure = 0, Success Rate = 100% |
   
   Validation was performed via manual benchmark reproduction.
   
   ### Validation
   
   - Before fix: `Stop()` kills in-flight requests as `context canceled`, low-QPS scenarios show 99.27% success rate
   - After fix: in-flight requests complete naturally, success rate 100.00%, no spurious errors
   - `go build ./tools/benchmark/client/...` passes
   - `go test ./tools/benchmark/...` passes
   
   ### Checklist
   - [x] I confirm the target branch is `develop`
   - [x] I have run `make fmt` to format my code
   - [x] I have run `make test` to run local tests
   - [ ] I have added tests that prove my fix is effective or that my feature works
   


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] fix(benchmark): drain in-flight requests before canceling ctx in engine.Stop() [dubbo-go]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #3677:
URL: https://github.com/apache/dubbo-go/pull/3677#issuecomment-5325594590

   ## [Codecov](https://app.codecov.io/gh/apache/dubbo-go/pull/3677?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :x: Patch coverage is `0%` with `1 line` in your changes missing coverage. Please review.
   :white_check_mark: Project coverage is 54.81%. Comparing base ([`60d1c2a`](https://app.codecov.io/gh/apache/dubbo-go/commit/60d1c2a949f0ee0da4be3fe09fb79d295491e040?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`91ece26`](https://app.codecov.io/gh/apache/dubbo-go/commit/91ece2675eb9f84b69b8f1a760977a8679cb7fe2?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   :warning: Report is 932 commits behind head on develop.
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/dubbo-go/pull/3677?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [tools/benchmark/client/engine/engine.go](https://app.codecov.io/gh/apache/dubbo-go/pull/3677?src=pr&el=tree&filepath=tools%2Fbenchmark%2Fclient%2Fengine%2Fengine.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-dG9vbHMvYmVuY2htYXJrL2NsaWVudC9lbmdpbmUvZW5naW5lLmdv) | 0.00% | [1 Missing :warning: ](https://app.codecov.io/gh/apache/dubbo-go/pull/3677?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@             Coverage Diff             @@
   ##           develop    #3677      +/-   ##
   ===========================================
   + Coverage    46.76%   54.81%   +8.05%     
   ===========================================
     Files          295      475     +180     
     Lines        17172    36796   +19624     
   ===========================================
   + Hits          8031    20171   +12140     
   - Misses        8287    15012    +6725     
   - Partials       854     1613     +759     
   ```
   </details>
   
   [:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/dubbo-go/pull/3677?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   </details>


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] fix(benchmark): drain in-flight requests before canceling ctx in engine.Stop() [dubbo-go]

Posted by "lizining1231 (via GitHub)" <gi...@apache.org>.
lizining1231 commented on code in PR #3677:
URL: https://github.com/apache/dubbo-go/pull/3677#discussion_r3803600323


##########
tools/benchmark/client/engine/engine.go:
##########
@@ -114,8 +114,8 @@ func (e *Engine) worker(benchmarkFunc BenchmarkFunc) {
 func (e *Engine) Stop() {
 	e.stopOnce.Do(func() {
 		close(e.stopChan)
-		e.cancel()
 		e.wg.Wait()
+		e.cancel()
 		logger.Info("[INFO] Benchmark completed")

Review Comment:
   谢谢你的评审!理论上确实可能永久阻塞
   你说得对,`context.WithTimeout` 到期后只是关闭 `Done()` channel,不会强制 kill 掉 goroutine。如果 `benchmarkFunc` 内部是一个裸的 `conn.Read()` 没有设 deadline,有可能永久阻塞
   
   但是我核实了一下,从实际代码来看
   
   ```go
   func(ctx context.Context) (time.Duration, error) {
       err := caller.Call(ctx)
   }
   ```
   `caller.Call(ctx)` 只有两种实现:
   
   | 实现 | 调用 | 底层实现 |
   |:---|:---|:---|
   | [dubbo_client.go#L83](https://github.com/apache/dubbo-go/blob/develop/tools/benchmark/client/clients/dubbo_client.go#L83) | `c.client.UnaryCall(ctx, req)` |  HTTP/2 transport,读响应时通过 `select { case <-ctx.Done() }` 监听 context 取消([h2_bundle.go#L9926](https://github.com/golang/go/blob/go1.26.5/src/net/http/h2_bundle.go#L9926)) |
   | [grpc_client.go#L70](https://github.com/apache/dubbo-go/blob/develop/tools/benchmark/client/clients/grpc_client.go#L70) | `c.client.UnaryCall(ctx, req)` | gRPC transport 通过 `select { case <-ctx.Done() }` 取消 stream([transport.go#L232](https://github.com/grpc/grpc-go/blob/v1.82.1/internal/transport/transport.go#L232)),同时将 deadline 编码为 `grpc-timeout` header 通知服务端([http2_client.go#L607-L614](https://github.com/grpc/grpc-go/blob/v1.82.1/internal/transport/http2_client.go#L607-L614)) |
   
   因此从ctx 层面看,30s 超时关闭;从transport 层面看,benchmarkFunc 也是30s超时关闭
   所以实际上不会永久阻塞



-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] fix(benchmark): drain in-flight requests before canceling ctx in engine.Stop() [dubbo-go]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #3677:
URL: https://github.com/apache/dubbo-go/pull/3677#issuecomment-5325452885

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3677) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3677&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3677&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3677&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3677&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3677&metric=new_duplicated_lines_density&view=list)  
     
   <!-- sqra-placement-anchor -->
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3677)
   
   


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] fix(benchmark): drain in-flight requests before canceling ctx in engine.Stop() [dubbo-go]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #3677:
URL: https://github.com/apache/dubbo-go/pull/3677#discussion_r3802645446


##########
tools/benchmark/client/engine/engine.go:
##########
@@ -114,8 +114,8 @@ func (e *Engine) worker(benchmarkFunc BenchmarkFunc) {
 func (e *Engine) Stop() {
 	e.stopOnce.Do(func() {
 		close(e.stopChan)
-		e.cancel()
 		e.wg.Wait()
+		e.cancel()
 		logger.Info("[INFO] Benchmark completed")

Review Comment:
   Waiting for `e.wg.Wait()` before calling `e.cancel()` can cause `Stop()` to block indefinitely if any in-flight work only terminates on context cancellation (or if `benchmarkFunc`/downstream code ignores `stopChan` and doesn’t reliably honor the per-request timeout in some edge cases). Consider implementing a bounded drain: wait for the waitgroup up to a configurable/grace timeout, then call `e.cancel()` to force shutdown (and optionally log that the grace period elapsed). This preserves the goal of avoiding spurious cancellations while preventing teardown hangs.



-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] fix(benchmark): drain in-flight requests before canceling ctx in engine.Stop() [dubbo-go]

Posted by "Alanxtl (via GitHub)" <gi...@apache.org>.
Alanxtl merged PR #3677:
URL: https://github.com/apache/dubbo-go/pull/3677


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org