Skip to content

fix(jindo): remove duplicate send on MetadataSyncDoneCh in jindocache and jindofsx - #6298

Open
neo0007777 wants to merge 1 commit into
fluid-cloudnative:masterfrom
neo0007777:fix/jindo-metadata-sync-duplicate-send
Open

neo0007777 wants to merge 1 commit into
fluid-cloudnative:masterfrom
neo0007777:fix/jindo-metadata-sync-duplicate-send

Conversation

@neo0007777

@neo0007777 neo0007777 commented Nov 26, 2026 •

Copy link
Copy Markdown

Ⅰ. Describe what this PR does

Removes the duplicate unguarded channel send resultChan <- result after base.SafeSend(resultChan, result) in syncMetadataInternal() for both JindoCacheEngine (pkg/ddc/jindocache/metadata.go) and JindoFSxEngine (pkg/ddc/jindofsx/metadata.go), and drops the leftover resultChan <- result inside the disabled comment block in pkg/ddc/jindo/metadata.go.

Previously, because MetadataSyncDoneCh is unbuffered and the receiver reads at most once before setting e.MetadataSyncDoneCh = nil, the second send blocked the goroutine forever on every completed metadata sync, leaking a goroutine and bypassing defer base.SafeClose(resultChan). Removing the duplicate send ensures each completed sync sends once via base.SafeSend, closes resultChan, and exits cleanly.

(Note: in jindocache and jindofsx, nothing outside the sync goroutine currently closes MetadataSyncDoneCh, so the goroutine leak is the reachable failure mode here; closing MetadataSyncDoneCh on shutdown like alluxio/vineyard is tracked in #6308.)

Ⅱ. Does this pull request fix one issue?

fixes #6297

Ⅲ. List the added test cases (unit test/integration test) if any, please explain if no tests are needed.

  • Added shared helper VerifyMetadataSyncChannelClosedOnce in pkg/utils/testutil/metadata_sync.go
  • Added focused TestSyncMetadataInternalChannelLifecycle in pkg/ddc/jindocache/metadata_test.go and pkg/ddc/jindofsx/metadata_test.go to verify that starting with MetadataSyncDoneCh == nil initializes the channel, clears it on follow-up sync, and closes the channel cleanly without blocking on a duplicate send.

Ⅳ. Describe how to verify it

Run the unit tests for testutil, jindocache, jindofsx, and jindo:

FLUID_UNIT_TEST=true go test -gcflags="all=-N -l" ./pkg/utils/testutil/... ./pkg/ddc/jindocache/... ./pkg/ddc/jindofsx/... ./pkg/ddc/jindo/...
go test -race -v ./pkg/ddc/jindocache -run TestSyncMetadataInternalChannelLifecycle
go test -race -v ./pkg/ddc/jindofsx -run TestSyncMetadataInternalChannelLifecycle

Ⅴ. Special notes for reviews

@neo0007777

Copy link
Copy Markdown
Author

Hi @cheyang @RongGu, could you please review this PR when you have a moment? It fixes #6297 by removing the duplicate channel send in jindocache and jindofsx metadata sync.

@neo0007777
neo0007777 force-pushed the fix/jindo-metadata-sync-duplicate-send branch from 088c4fc to dc85e48 Compare November 26, 2026 15:52
@cheyang
cheyang requested a balanced review from Copilot November 27, 2026 04:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the change removing duplicate metadata-sync result sends.

No open issues 🎉

What changed in this PR

Fixes #6297 by removing duplicate metadata-sync result sends in JindoCache and JindoFSx, preventing the second send from blocking indefinitely or panicking on a closed channel.

Changes:

  • Retains a single guarded SafeSend in both engines, matching the other runtime implementations.
  • Adds a shared regression-test helper to check channel initialization, cleanup, and closure without a duplicate result.
  • Extends both engines’ tests to exercise synchronization starting with a nil result channel.
File Description
pkg/​utils/​testutil/​metadata_sync.go Adds shared checks for metadata-sync channel completion.
pkg/​ddc/​jindofsx/​metadata.go Removes the duplicate unguarded result send.
pkg/​ddc/​jindofsx/​metadata_test.go Adds regression coverage using the shared helper.
pkg/​ddc/​jindocache/​metadata.go Removes the duplicate unguarded result send.
pkg/​ddc/​jindocache/​metadata_test.go Adds regression coverage using the shared helper.

Review effort: Balanced

@cheyang cheyang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two independent reviews of this fix for #6297, and both came back clean.

First, the premise is real: on the merge base, the bare resultChan <- result after base.SafeSend in syncMetadataInternal() leaks one goroutine per completed metadata sync in both jindocache and jindofsx — we each reproduced it with our own contract tests (a second value is observable on MetadataSyncDoneCh, goroutine count 3→4 and never returns, so the deferred SafeClose is starved). One nuance worth recording for posterity: the issue's other failure mode, a panic on send to a closed channel, is not actually reachable in these engines — nothing outside the sync goroutine ever closes the channel there — so the leak is the real story, and this PR removes both modes anyway.

On head, the contract holds: exactly one send, the channel gets closed, the goroutine exits, in both engines, under -race. The full suites for pkg/ddc/jindocache, pkg/ddc/jindofsx, pkg/ddc/base, and pkg/utils/testutil all pass, and the new regression tests provably bite — re-applying the deleted line, or grafting the PR's test onto the base code, turns them red. The diff is also the right shape: a one-line deletion per engine, matching the SafeSend-only pattern every other engine already follows. Required CI (DCO, SonarCloud) is green at this head.

No blocking findings from either reviewer; the only meaningful disagreement in the debate was over the git-history lineage of a dead commented-out line, not over the fix.

Next round

[MUST] (none — nothing gates merge from either review; all acceptance criteria pass and required CI is green at this head)
[SHOULD] optionally drop the dead resultChan <- result text at pkg/ddc/jindo/metadata.go:164 (inside a commented-out block — pre-existing, and per the corrected history it is not the origin of the live bug, just greppable residue worth removing); consider a follow-up issue to add the alluxio-style base.SafeClose(e.MetadataSyncDoneCh) to jindocache/jindofsx shutdown paths (pre-existing minor: a never-consumed sync still parks its sender goroutine, and the engine object with it, until process exit); optionally split the channel-lifecycle check into its own test function for cleaner failure attribution
[Filed] (no issues filed this round)

Reviewer C (Copilot) also reviewed this head and raised no findings.

Both verification harnesses — with raw results and a one-command re-verify.sh — live on the reviewer fork: verify/jindo-metadata-dup-send-claude and verify/jindo-metadata-dup-send-codex.

Non-blocking observations (4) — not part of this round's ask; fix now, follow up, or file an issue as you see fit
  • pkg/ddc/jindocache/metadata.go:141 [minor] — pre-existing, not introduced by this PR — jindocache/jindofsx never close MetadataSyncDoneCh on engine shutdown (pre-existing)
    Unlike alluxio (pkg/ddc/alluxio/shutdown.go:52-53) and vineyard (pkg/ddc/vineyard/shut_down.go:39-40), the jindocache and jindofsx engines never close MetadataSyncDoneCh on engine shutdown. This PR fixes the per-completed-sync goroutine leak, but if a sync result is never consumed (dataset removed mid-sync, runtime.Spec.Master.Disabled flipped, or UfsTotal set through another path while a sync is in flight), the sender goroutine stays parked inside base.SafeSend until process exit — and, because its closure captures the engine, it pins the entire JindoCacheEngine/JindoFSxEngine object (client, runtime, log) for process lifetime. Pre-existing, not introduced by this PR; suggest a follow-up issue adding base.SafeClose(e.MetadataSyncDoneCh) to both engines' shutdown paths, matching the alluxio pattern. Same in pkg/ddc/jindofsx/metadata.go:141.
  • pkg/ddc/jindocache/metadata.go:178 [nit] — Issue/PR overstate the panic-on-closed-channel mechanism
    The issue #6297 / PR body claim that the duplicate send 'panicked with send on closed channel if the channel had already been closed' is not reachable in jindocache/jindofsx: nothing outside the sync goroutine ever closes MetadataSyncDoneCh in those engines. The real, reproduced defect is the goroutine leak, which this PR fixes. Purely an accuracy note so future debugging of this code does not chase an unreachable panic path; the fix is correct regardless.
  • pkg/ddc/jindo/metadata.go:164 [nit] — pre-existing, not introduced by this PR — Leftover duplicate-send line inside commented-out block in jindo engine
    pkg/ddc/jindo/metadata.go:164 still contains 'resultChan <- result' inside a /* ... */ commented-out block (the disabled LoadMetadataWithoutTimeout early-return path, roughly lines 154-166). It is dead text but greppable residue of exactly the footgun this PR fixes; deleting it would prevent a future copy-paste reintroduction. Pre-existing, strictly optional. Note: this block is NOT the origin of the live bug — per git history, the duplicate was born in-place in jindofsx (#2536 added SafeSend above the existing bare send without deleting it, after #1801 created the file) and propagated to jindocache by #3346; the comment block was disabled earlier by #977.
  • pkg/ddc/jindocache/metadata_test.go:352 [nit] — Channel-lifecycle check appended as tail block inside TestSyncMetadataInternal
    The new async-channel verification via testutil.VerifyMetadataSyncChannelClosedOnce(engines[1].syncMetadataInternal, ...) is appended as a tail block inside the existing table test TestSyncMetadataInternal, whose testCase list still only exercises engines[0]. A separate focused test function (e.g. TestSyncMetadataInternalChannelLifecycle) would make failures attributable at a glance instead of surfacing as a generic TestSyncMetadataInternal failure. Works correctly as-is (verified: the block fails on base code and passes on head, also under -race; engines[1] starts with MetadataSyncDoneCh: nil so the block takes the start-sync branch, and the accessor closure reads the same struct copy the method mutates — no aliasing hazard). Same shape in pkg/ddc/jindofsx/metadata_test.go:352.
Verified review delta
  • F3-no-shutdown-close-metadata-channels: open (preexisting)
  • F1-panic-claim-unreachable: open (initial-pr)
  • F2-jindo-commented-dup-send: open (preexisting)
  • F4-channel-lifecycle-test-structure: open (initial-pr)

Code: clear. CI: success; attribution: unknown. Required CI checks still apply.

… and jindofsx

Signed-off-by: Shiva Sharma <shivaumj@gmail.com>
@neo0007777
neo0007777 force-pushed the fix/jindo-metadata-sync-duplicate-send branch from dc85e48 to eb524f4 Compare November 27, 2026 10:42
@neo0007777

Copy link
Copy Markdown
Author

Thanks @cheyang for the thorough review! Updated the PR to address all four notes:

  1. Clarified the PR description to accurately reflect that the goroutine leak is the reachable failure mode in jindocache/jindofsx.
  2. Dropped the dead resultChan <- result inside the comment block at pkg/ddc/jindo/metadata.go:164.
  3. Split the channel lifecycle verification into dedicated TestSyncMetadataInternalChannelLifecycle functions in both jindocache and jindofsx.
  4. Filed [BUG] jindocache/jindofsx: Shutdown does not close MetadataSyncDoneCh #6308 to track closing MetadataSyncDoneCh on shutdown in jindocache and jindofsx.

All unit tests and -race checks for jindocache, jindofsx, jindo, and testutil pass locally.

@sonarqubecloud

Copy link
Copy Markdown

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.

[BUG] jindocache/jindofsx: duplicate send on unbuffered MetadataSyncDoneCh leaks goroutines and can panic

3 participants