Skip to content

Commit 5fb4283

Browse files
authored
prevent deadlock on close (#17)
1 parent da3e960 commit 5fb4283

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

dsqueue.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ func (q *DSQueue) GetN(n int) ([][]byte, error) {
132132
if n == 0 {
133133
return nil, nil
134134
}
135-
rsp := make(chan getResponse)
135+
// Buffer response channel so write can happen even if reader gone.
136+
rsp := make(chan getResponse, 1)
136137
req := getRequest{
137138
n: n,
138139
rsp: rsp,

dsqueue_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ func BenchmarkGetN(b *testing.B) {
414414
queue := dsqueue.New(ds, dsqName, dsqueue.WithDedupCacheSize(0))
415415
defer queue.Close()
416416

417-
cids := random.Cids(25)
417+
cids := random.Cids(64)
418418

419419
b.ResetTimer()
420420
b.ReportAllocs()
@@ -423,7 +423,7 @@ func BenchmarkGetN(b *testing.B) {
423423
queue.Put(c.Bytes())
424424
}
425425

426-
outItems, err := queue.GetN(50)
426+
outItems, err := queue.GetN(100)
427427
if err != nil {
428428
b.Fatal(err)
429429
}

0 commit comments

Comments
 (0)