Skip to content

Commit fc8a89f

Browse files
Address panic on closing a previously closed channel (#1613)
+ Fixes: #1609 panic: close of closed channel goroutine 68 [running]: github.com/blevesearch/bleve/v2/index/scorch.(*closeChWrapper).close(0xc000346b80) /Users/runner/work/bleve/bleve/index/scorch/merge.go:228 +0x99 github.com/blevesearch/bleve/v2/index/scorch.(*closeChWrapper).listen(0xc000346b80) /Users/runner/work/bleve/bleve/index/scorch/merge.go:235 +0x1cd created by github.com/blevesearch/bleve/v2/index/scorch.(*Scorch).planMergeAtSnapshot /Users/runner/work/bleve/bleve/index/scorch/merge.go:275 +0x4ba
1 parent 5ab6887 commit fc8a89f

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

index/scorch/merge.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -209,32 +209,32 @@ func (s *Scorch) parseMergePlannerOptions() (*mergeplan.MergePlanOptions,
209209
}
210210

211211
type closeChWrapper struct {
212-
ch1 chan struct{}
213-
ctx context.Context
214-
closeCh chan struct{}
212+
ch1 chan struct{}
213+
ctx context.Context
214+
closeCh chan struct{}
215+
cancelCh chan struct{}
215216
}
216217

217218
func newCloseChWrapper(ch1 chan struct{},
218219
ctx context.Context) *closeChWrapper {
219-
return &closeChWrapper{ch1: ch1,
220-
ctx: ctx,
221-
closeCh: make(chan struct{})}
220+
return &closeChWrapper{
221+
ch1: ch1,
222+
ctx: ctx,
223+
closeCh: make(chan struct{}),
224+
cancelCh: make(chan struct{}),
225+
}
222226
}
223227

224228
func (w *closeChWrapper) close() {
225-
select {
226-
case <-w.closeCh:
227-
default:
228-
close(w.closeCh)
229-
}
229+
close(w.closeCh)
230230
}
231231

232232
func (w *closeChWrapper) listen() {
233233
select {
234234
case <-w.ch1:
235-
w.close()
235+
close(w.cancelCh)
236236
case <-w.ctx.Done():
237-
w.close()
237+
close(w.cancelCh)
238238
case <-w.closeCh:
239239
}
240240
}
@@ -320,7 +320,7 @@ func (s *Scorch) planMergeAtSnapshot(ctx context.Context,
320320

321321
atomic.AddUint64(&s.stats.TotFileMergeZapBeg, 1)
322322
newDocNums, _, err := s.segPlugin.Merge(segmentsToMerge, docsToDrop, path,
323-
cw.closeCh, s)
323+
cw.cancelCh, s)
324324
atomic.AddUint64(&s.stats.TotFileMergeZapEnd, 1)
325325

326326
fileMergeZapTime := uint64(time.Since(fileMergeZapStartTime))

0 commit comments

Comments
 (0)