Skip to content
This repository has been archived by the owner on Oct 30, 2024. It is now read-only.

Commit

Permalink
fix: defer mupdf unlock to prevent deadlock
Browse files Browse the repository at this point in the history
  • Loading branch information
iwilltry42 committed Oct 9, 2024
1 parent 058b421 commit 2fb4119
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions pkg/datastore/documentloader/pdf/mupdf/pdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func (l *PDF) Load(ctx context.Context) ([]vs.Document, error) {
// We need a lock here, since MuPDF is not thread-safe and there are some edge cases that can cause a CGO panic.
// See https://github.com/gptscript-ai/knowledge/issues/135
mupdfLock.Lock()
defer mupdfLock.Unlock()
g, childCtx := errgroup.WithContext(ctx)
g.SetLimit(l.opts.NumThread)
for pageNum := 0; pageNum < numPages; pageNum++ {
Expand Down Expand Up @@ -136,10 +137,7 @@ func (l *PDF) Load(ctx context.Context) ([]vs.Document, error) {
})
}

err := g.Wait()
mupdfLock.Unlock()

return docs, err
return docs, g.Wait()
}

// LoadAndSplit loads PDF documents from the provided reader and splits them using the specified text splitter.
Expand Down

0 comments on commit 2fb4119

Please sign in to comment.