Skip to content

Commit

Permalink
Fix stalled event processing
Browse files Browse the repository at this point in the history
  • Loading branch information
jwoloch committed Oct 16, 2024
1 parent e7f60f9 commit c10ca11
Showing 1 changed file with 10 additions and 4 deletions.
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

0 comments on commit c10ca11

Please sign in to comment.