Skip to content

Commit e811b38

Browse files
otherviewzzyalbert
authored andcommitted
core/bloombits: avoid crash when storing errors of different type (ethereum#23437)
This fixes a rare crash which could occur when two different errors happened in the same bloombits.MatcherSession.
1 parent 63461d8 commit e811b38

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

core/bloombits/matcher.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -510,8 +510,9 @@ type MatcherSession struct {
510510
closer sync.Once // Sync object to ensure we only ever close once
511511
quit chan struct{} // Quit channel to request pipeline termination
512512

513-
ctx context.Context // Context used by the light client to abort filtering
514-
err atomic.Value // Global error to track retrieval failures deep in the chain
513+
ctx context.Context // Context used by the light client to abort filtering
514+
err error // Global error to track retrieval failures deep in the chain
515+
errLock sync.Mutex
515516

516517
pend sync.WaitGroup
517518
}
@@ -529,10 +530,10 @@ func (s *MatcherSession) Close() {
529530

530531
// Error returns any failure encountered during the matching session.
531532
func (s *MatcherSession) Error() error {
532-
if err := s.err.Load(); err != nil {
533-
return err.(error)
534-
}
535-
return nil
533+
s.errLock.Lock()
534+
defer s.errLock.Unlock()
535+
536+
return s.err
536537
}
537538

538539
// allocateRetrieval assigns a bloom bit index to a client process that can either
@@ -630,7 +631,9 @@ func (s *MatcherSession) Multiplex(batch int, wait time.Duration, mux chan chan
630631

631632
result := <-request
632633
if result.Error != nil {
633-
s.err.Store(result.Error)
634+
s.errLock.Lock()
635+
s.err = result.Error
636+
s.errLock.Unlock()
634637
s.Close()
635638
}
636639
s.deliverSections(result.Bit, result.Sections, result.Bitsets)

0 commit comments

Comments
 (0)