Skip to content

Commit 6a85bee

Browse files
committed
blockservice: fix panic when closing an offline blockservice
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.
1 parent 6d5475f commit 6a85bee

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

blockservice/blockservice.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,9 @@ func (s *blockService) DeleteBlock(ctx context.Context, c cid.Cid) error {
444444

445445
func (s *blockService) Close() error {
446446
logger.Debug("blockservice is shutting down...")
447+
if s.exchange == nil {
448+
return nil
449+
}
447450
return s.exchange.Close()
448451
}
449452

0 commit comments

Comments
 (0)