File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -330,7 +330,18 @@ func (b *ReadOnly) Roots() ([]cid.Cid, error) {
330
330
}
331
331
332
332
// Close closes the underlying reader if it was opened by OpenReadOnly.
333
+ //
334
+ // Note that this call may block if any blockstore operations are currently in
335
+ // progress, including an AllKeysChan that hasn't been fully consumed or
336
+ // cancelled.
333
337
func (b * ReadOnly ) Close () error {
338
+ b .mu .Lock ()
339
+ defer b .mu .Unlock ()
340
+
341
+ return b .closeWithoutMutex ()
342
+ }
343
+
344
+ func (b * ReadOnly ) closeWithoutMutex () error {
334
345
if b .carv2Closer != nil {
335
346
return b .carv2Closer .Close ()
336
347
}
Original file line number Diff line number Diff line change @@ -343,7 +343,12 @@ func (b *ReadWrite) Finalize() error {
343
343
defer b .mu .Unlock ()
344
344
// TODO check if add index option is set and don't write the index then set index offset to zero.
345
345
b .header = b .header .WithDataSize (uint64 (b .dataWriter .Position ()))
346
- defer b .Close ()
346
+
347
+ // Note that we can't use b.Close here, as that tries to grab the same
348
+ // mutex we're holding here.
349
+ // TODO: should we check the error here? especially with OpenReadWrite,
350
+ // we should care about close errors.
351
+ defer b .closeWithoutMutex ()
347
352
348
353
// TODO if index not needed don't bother flattening it.
349
354
fi , err := b .idx .flatten ()
You can’t perform that action at this time.
0 commit comments