Skip to content

Commit

Permalink
blockservice: fix panic when closing an offline blockservice
Browse files Browse the repository at this point in the history
blockservice is explicitely tolerent to having a nil exchange.
The constructor even logs that as running an offline blockservice.

Everything is tolerent except close, which panics.

It is confusing for consumers to only have to call close based on if it's online or offline.
They could also instead call close directly on the exchange (then we could remove blockservice's Close method).

Anyway here is as a simple fix, add a nil check.
  • Loading branch information
Jorropo authored and hacdias committed Jan 4, 2024
1 parent a001f98 commit 79cace5
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions blockservice/blockservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,9 @@ func (s *blockService) DeleteBlock(ctx context.Context, c cid.Cid) error {

func (s *blockService) Close() error {
logger.Debug("blockservice is shutting down...")
if s.exchange == nil {
return nil
}
return s.exchange.Close()
}

Expand Down

0 comments on commit 79cace5

Please sign in to comment.