Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix stalled event processing #109

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions blockchain/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,10 @@ func (c *Client) ListenEvents(

// Query historical headers.
histHeadersC := make(chan types.Header)
defer close(histHeadersC)

g.Go(func() error {
defer close(histHeadersC)

firstLiveHeader, err := getFirstLiveHeader(ctx, liveHeadersC)
if err != nil {
return err
Expand Down Expand Up @@ -140,9 +141,10 @@ func (c *Client) ListenEvents(

// Sequence historical and live headers.
headersC := make(chan types.Header, 2)
defer close(headersC)

g.Go(func() error {
defer close(headersC)

if err = forwardHeaders(ctx, histHeadersC, headersC); err != nil {
return err
}
Expand All @@ -159,7 +161,11 @@ func (c *Client) ListenEvents(
select {
case <-ctx.Done():
return ctx.Err()
case header := <-headersC:
case header, ok := <-headersC:
if !ok {
return ErrHeaderChannelClosed
}

if header.Number < begin {
continue
}
Expand Down Expand Up @@ -227,7 +233,7 @@ func forwardHeaders(ctx context.Context, from <-chan types.Header, to chan types
return ctx.Err()
case header, ok := <-from:
if !ok {
return ErrHeaderChannelClosed
return nil
}

select {
Expand Down
Loading