Introduce context.Context support to prevent goroutine leaks#386
Merged
Conversation
Add ComputeWithContext methods to all indicators and WithContext variants to all helper functions, enabling cancellation support through context.Context. Old Compute methods are preserved as deprecated shims that delegate to ComputeWithContext with context.Background(). Fixes #372
This reverts commit 863b91c.
This reverts commit 0349cf2.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #386 +/- ##
==========================================
- Coverage 94.02% 91.90% -2.13%
==========================================
Files 225 226 +1
Lines 6530 7162 +632
==========================================
+ Hits 6140 6582 +442
- Misses 309 490 +181
- Partials 81 90 +9 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- TestComputeMaWithContextFallback: covers the fallback path when Ma does not implement MaWithContext - TestComputeStrategyWithContextFallback: covers the fallback path when Strategy does not implement StrategyWithContext - TestCancellationWithApplyWindow, TestCancellationWithEchoSkip: extend cancellation coverage to more helper functions
- Propagate ctx through ChangeWithContext -> SubtractWithContext - Propagate ctx through ChangeRatioWithContext -> DivideWithContext, ChangeWithContext - Propagate ctx through ChangePercentWithContext -> MultiplyByWithContext, ChangeRatioWithContext - Fix stdlib import ordering in connors_rsi.go and pivot_point.go
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Summary
Adds
context.Contextcancellation support to every channel-based operator inhelper/and every indicatorComputemethod. This prevents goroutine leaks when downstream consumers stop reading from output channels (e.g., early exit, timeout, strategy condition satisfied).Changes
ComputeWithContext(ctx, ...)on all indicators,*WithContext(ctx, ...)on all helper functionsCompute(...)methods preserved as deprecated shims delegating toComputeWithContext(context.Background(), ...)ctx.Done()alongside channel operationsStrategyWithContextinterface withComputeWithContext;ComputeStrategyWithContexttype-asserts and falls back to oldStrategy.ComputeMaWithContext[T]interface for discoverable context-aware MA dispatchcancellation_test.gofor helper cancellation coverageScope
216 files changed, ~7,770 insertions / ~3,303 deletions.
Fixes #372