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 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 committed Dec 29, 2023
1 parent 6d5475f commit 6a85bee
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 @@ -444,6 +444,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
}

Check warning on line 449 in blockservice/blockservice.go

View check run for this annotation

Codecov / codecov/patch

blockservice/blockservice.go#L448-L449

Added lines #L448 - L449 were not covered by tests
return s.exchange.Close()
}

Expand Down

0 comments on commit 6a85bee

Please sign in to comment.