mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-10 15:46:26 -04:00
Synchronize ViewBufferManager.Close with a starting task (#5786)
Fixes a race condition related to ViewBufferManager's stopCurrentTask field.
This commit is contained in:
commit
d94ca63e6d
|
|
@ -393,14 +393,21 @@ func (self *ViewBufferManager) NewCmdTask(start func() (Cmd, io.Reader), prefix
|
|||
|
||||
// Close closes the task manager, killing whatever task may currently be running
|
||||
func (self *ViewBufferManager) Close() {
|
||||
if self.stopCurrentTask == nil {
|
||||
// stopCurrentTask is written by NewTask's goroutine under waitingMutex (and
|
||||
// so is the sync.Once it closes over), so read it under the lock and call
|
||||
// the captured value; a task starting on shutdown must not race us here.
|
||||
self.waitingMutex.Lock()
|
||||
stopCurrentTask := self.stopCurrentTask
|
||||
self.waitingMutex.Unlock()
|
||||
|
||||
if stopCurrentTask == nil {
|
||||
return
|
||||
}
|
||||
|
||||
c := make(chan struct{})
|
||||
|
||||
go utils.Safe(func() {
|
||||
self.stopCurrentTask()
|
||||
stopCurrentTask()
|
||||
c <- struct{}{}
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue