mirror of
https://github.com/mattermost/mattermost.git
synced 2026-05-28 04:35:04 -04:00
[MM-49003] Close the pipe reader when done reading (#21854)
This commit is contained in:
parent
e58b6ffa3e
commit
f3e8a0b72f
1 changed files with 8 additions and 10 deletions
|
|
@ -44,26 +44,24 @@ func MakeWorker(jobServer *jobs.JobServer, app AppIface) model.Worker {
|
|||
|
||||
rd, wr := io.Pipe()
|
||||
|
||||
errCh := make(chan *model.AppError, 1)
|
||||
go func() {
|
||||
defer close(errCh)
|
||||
// Try to write without a timeout
|
||||
_, 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)
|
||||
if err := wr.Close(); err != nil {
|
||||
mlog.Warn("Worker: error closing writer")
|
||||
}
|
||||
wr.Close() // Close never returns an error
|
||||
|
||||
if appErr != nil {
|
||||
return appErr
|
||||
}
|
||||
|
||||
if appErr := <-errCh; appErr != nil {
|
||||
return appErr
|
||||
}
|
||||
return nil
|
||||
}
|
||||
worker := jobs.NewSimpleWorker(jobName, jobServer, execute, isEnabled)
|
||||
|
|
|
|||
Loading…
Reference in a new issue