Skip to content

Fix goroutine leak: add missing return after doneChan send in LocateSchemaPropertyNodeByJSONPath#271

Open
SebTardif wants to merge 1 commit intopb33f:mainfrom
SebTardif:fix/goroutine-leak-empty-path
Open

Fix goroutine leak: add missing return after doneChan send in LocateSchemaPropertyNodeByJSONPath#271
SebTardif wants to merge 1 commit intopb33f:mainfrom
SebTardif:fix/goroutine-leak-empty-path

Conversation

@SebTardif
Copy link
Copy Markdown

Problem

In LocateSchemaPropertyNodeByJSONPath, when the converted path is empty, the goroutine sends on doneChan to signal the parent to return, but does not return itself:

if path == "" {
    doneChan <- true
    // missing return — falls through to locatedNodeChan send
}

After the parent receives from doneChan via select and returns nil, the goroutine continues execution and eventually blocks forever trying to send on the unbuffered locatedNodeChan (which no longer has a receiver). This is a goroutine leak.

The defer recovery block at lines 20-24 correctly relies on implicit return after sending on doneChan. The explicit empty-path check should do the same.

Introduced in PR #20 (2023-09-02).

Fix

Add return after doneChan <- true so the goroutine exits cleanly.

Testing

All existing tests pass. A red-green test is not feasible because the upstream ConvertComponentIdIntoFriendlyPathSearch currently never returns an empty path (always at least "$."), making the if 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.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 10, 2026

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 98.06%. Comparing base (f95f219) to head (eead482).

Files with missing lines Patch % Lines
schema_validation/locate_schema_property.go 0.00% 1 Missing ⚠️
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              
Flag Coverage Δ
unittests 98.06% <0.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant