Skip to content

fix: don't close signal channel in walker goroutines to prevent panic#45

Merged
sebogh merged 1 commit into
heimdalr:masterfrom
Yanhu007:fix/walker-close-signal-panic
Apr 14, 2026
Merged

fix: don't close signal channel in walker goroutines to prevent panic#45
sebogh merged 1 commit into
heimdalr:masterfrom
Yanhu007:fix/walker-close-signal-panic

Conversation

@Yanhu007

Copy link
Copy Markdown
Contributor

Fixes #37

Problem

AncestorsWalker and DescendantsWalker close both ids and signal channels when the walk completes. If the consumer stops at the last vertex and then sends on the signal channel, it panics:

panic: send on closed channel

Root Cause

The goroutine closes signal after the walk finishes, but the consumer may try to send on it after receiving the last vertex:

// goroutine
close(ids)
close(signal) // ← closes signal

// consumer
signal <- true // ← panic: send on closed channel

Fix

Remove close(signal) from both walker goroutines. The signal channel is a send-only channel from the consumer's perspective — the goroutine should not close it. The consumer signals the goroutine to stop; the goroutine signals the consumer by closing ids.

All existing tests pass.

AncestorsWalker and DescendantsWalker close both 'ids' and
'signal' channels when the walk completes. If the consumer
stops at the last vertex and then sends on the signal channel,
it panics with 'send on closed channel'.

The signal channel is owned by the consumer (they send on it
to stop the walk). The goroutine should not close it — only
close 'ids' to signal completion to the consumer.

Fixes heimdalr#37
@sebogh sebogh merged commit 62742fd into heimdalr:master Apr 14, 2026
10 checks passed
@sebogh

sebogh commented Apr 14, 2026

Copy link
Copy Markdown
Collaborator

Thanks @Yanhu007

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.

AncestorsWalker panics if we try to stop at the last vertex

2 participants