Skip to content

Commit 79cace5

Browse files
Jorropohacdias
authored andcommitted
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 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.
1 parent a001f98 commit 79cace5

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
@@ -422,6 +422,9 @@ func (s *blockService) DeleteBlock(ctx context.Context, c cid.Cid) error {
422422

423423
func (s *blockService) Close() error {
424424
logger.Debug("blockservice is shutting down...")
425+
if s.exchange == nil {
426+
return nil
427+
}
425428
return s.exchange.Close()
426429
}
427430

0 commit comments

Comments
 (0)