summaryrefslogtreecommitdiff
path: root/vendor/codeberg.org/gruf
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2023-03-24 23:07:50 +0000
committerLibravatar GitHub <noreply@github.com>2023-03-24 23:07:50 +0000
commit883dc5476bde5b34cd4c2086a80a56db0c88e44f (patch)
treefefd5f5364a33aec761313635af6c38d183a8afc /vendor/codeberg.org/gruf
parent[chore] Refactor account deleting/block logic, tidy up some other processing ... (diff)
downloadgotosocial-883dc5476bde5b34cd4c2086a80a56db0c88e44f.tar.xz
bump go-runners version to fix possible race in Processing{Media,Emoji} (#1646)
Signed-off-by: kim <grufwub@gmail.com>
Diffstat (limited to 'vendor/codeberg.org/gruf')
-rw-r--r--vendor/codeberg.org/gruf/go-runners/process.go36
1 files changed, 21 insertions, 15 deletions
diff --git a/vendor/codeberg.org/gruf/go-runners/process.go b/vendor/codeberg.org/gruf/go-runners/process.go
index 908e6edca..ca39ac0d0 100644
--- a/vendor/codeberg.org/gruf/go-runners/process.go
+++ b/vendor/codeberg.org/gruf/go-runners/process.go
@@ -15,8 +15,7 @@ type Processable func() error
// that only a single instance of it is ever running at any one time.
type Processor struct {
mutex sync.Mutex
- state uint32
- wait sync.WaitGroup
+ wait *sync.WaitGroup
err *error
}
@@ -26,24 +25,34 @@ func (p *Processor) Process(proc Processable) (err error) {
// Acquire state lock.
p.mutex.Lock()
- if p.state != 0 {
+ if p.wait != nil {
// Already running.
//
- // Get current err ptr.
+ // Get current ptrs.
+ waitPtr := p.wait
errPtr := p.err
- // Wait until finish.
+ // Free state lock.
p.mutex.Unlock()
- p.wait.Wait()
+
+ // Wait for finish.
+ waitPtr.Wait()
return *errPtr
}
- // Reset error ptr.
- p.err = new(error)
+ // Alloc waiter for new process.
+ var wait sync.WaitGroup
+
+ // No need to alloc new error as
+ // we use the alloc'd named error
+ // return required for panic handling.
+
+ // Reset ptrs.
+ p.wait = &wait
+ p.err = &err
// Set started.
- p.wait.Add(1)
- p.state = 1
+ wait.Add(1)
p.mutex.Unlock()
defer func() {
@@ -57,15 +66,12 @@ func (p *Processor) Process(proc Processable) (err error) {
err = fmt.Errorf("caught panic: %v", r)
}
- // Store error.
- *p.err = err
-
// Mark done.
- p.wait.Done()
+ wait.Done()
// Set stopped.
p.mutex.Lock()
- p.state = 0
+ p.wait = nil
p.mutex.Unlock()
}()