Fix goroutine leak: add missing return after doneChan send in LocateSchemaPropertyNodeByJSONPath#271
Open
SebTardif wants to merge 1 commit intopb33f:mainfrom
Open
Conversation
…chemaPropertyNodeByJSONPath
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #271 +/- ##
==========================================
- Coverage 98.08% 98.06% -0.02%
==========================================
Files 64 64
Lines 6987 6988 +1
==========================================
Hits 6853 6853
- Misses 133 134 +1
Partials 1 1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Problem
In
LocateSchemaPropertyNodeByJSONPath, when the converted path is empty, the goroutine sends ondoneChanto signal the parent to return, but does notreturnitself:After the parent receives from
doneChanviaselectand returnsnil, the goroutine continues execution and eventually blocks forever trying to send on the unbufferedlocatedNodeChan(which no longer has a receiver). This is a goroutine leak.The
deferrecovery block at lines 20-24 correctly relies on implicit return after sending ondoneChan. The explicit empty-path check should do the same.Introduced in PR #20 (2023-09-02).
Fix
Add
returnafterdoneChan <- trueso the goroutine exits cleanly.Testing
All existing tests pass. A red-green test is not feasible because the upstream
ConvertComponentIdIntoFriendlyPathSearchcurrently never returns an empty path (always at least"$."), making theif path == ""branch unreachable through the public API. The fix is a structural correctness issue: send-without-return on an unbuffered channel in a goroutine is a textbook leak pattern.