[MM-49003] Close the pipe reader when done reading (#21854)

Этот коммит содержится в:
Tim Scheuermann
2022-12-16 16:29:26 +01:00
коммит произвёл GitHub
родитель e58b6ffa3e
Коммит f3e8a0b72f

Просмотреть файл

@@ -44,26 +44,24 @@ func MakeWorker(jobServer *jobs.JobServer, app AppIface) model.Worker {
rd, wr := io.Pipe() rd, wr := io.Pipe()
errCh := make(chan *model.AppError, 1)
go func() { go func() {
defer close(errCh)
// Try to write without a timeout
_, appErr := app.WriteFileContext(context.Background(), rd, filepath.Join(outPath, exportFilename)) _, appErr := app.WriteFileContext(context.Background(), rd, filepath.Join(outPath, exportFilename))
errCh <- appErr if appErr != nil {
// we close the reader here to prevent a deadlock when the bulk exporter tries to
// write into the pipe while app.WriteFile has already returned. The error will be
// returned by the writer part of the pipe when app.BulkExport tries to call
// wr.Write() on it.
rd.CloseWithError(appErr) // CloseWithError never returns an error
}
}() }()
appErr := app.BulkExport(request.EmptyContext(app.Log()), wr, outPath, opts) appErr := app.BulkExport(request.EmptyContext(app.Log()), wr, outPath, opts)
if err := wr.Close(); err != nil { wr.Close() // Close never returns an error
mlog.Warn("Worker: error closing writer")
}
if appErr != nil { if appErr != nil {
return appErr return appErr
} }
if appErr := <-errCh; appErr != nil {
return appErr
}
return nil return nil
} }
worker := jobs.NewSimpleWorker(jobName, jobServer, execute, isEnabled) worker := jobs.NewSimpleWorker(jobName, jobServer, execute, isEnabled)