From 883dc5476bde5b34cd4c2086a80a56db0c88e44f Mon Sep 17 00:00:00 2001 From: kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com> Date: Fri, 24 Mar 2023 23:07:50 +0000 Subject: [PATCH] bump go-runners version to fix possible race in Processing{Media,Emoji} (#1646) Signed-off-by: kim --- go.mod | 2 +- go.sum | 4 +-- .../codeberg.org/gruf/go-runners/process.go | 36 +++++++++++-------- vendor/modules.txt | 2 +- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/go.mod b/go.mod index be2f8223..60343c27 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( codeberg.org/gruf/go-kv v1.6.1 codeberg.org/gruf/go-logger/v2 v2.2.1 codeberg.org/gruf/go-mutexes v1.1.5 - codeberg.org/gruf/go-runners v1.6.0 + codeberg.org/gruf/go-runners v1.6.1 codeberg.org/gruf/go-sched v1.2.3 codeberg.org/gruf/go-store/v2 v2.2.1 github.com/KimMachineGun/automemlimit v0.2.4 diff --git a/go.sum b/go.sum index 8ae0942b..f559eb72 100644 --- a/go.sum +++ b/go.sum @@ -79,8 +79,8 @@ codeberg.org/gruf/go-mutexes v1.1.5 h1:8Y8DwCGf24MyzOSaPvLrtk/B4ecVx4z+fppL6dY+P codeberg.org/gruf/go-mutexes v1.1.5/go.mod h1:1j/6/MBeBQUedAtAtysLLnBKogfOZAxdym0E3wlaBD8= codeberg.org/gruf/go-pools v1.1.0 h1:LbYP24eQLl/YI1fSU2pafiwhGol1Z1zPjRrMsXpF88s= codeberg.org/gruf/go-pools v1.1.0/go.mod h1:ZMYpt/DjQWYC3zFD3T97QWSFKs62zAUGJ/tzvgB9D68= -codeberg.org/gruf/go-runners v1.6.0 h1:cAHKxMgtkb3v6it4qZZs4fo+yYgICNCrYvFlayuvSdk= -codeberg.org/gruf/go-runners v1.6.0/go.mod h1:QRcSExqXX8DM0rm8Xs6qX7baOzyvw0JIe4mu3TsQT+Y= +codeberg.org/gruf/go-runners v1.6.1 h1:0KNiEfGnmNUs9intqxEAWqIKUyxVOmYTtn3kPVOHsjQ= +codeberg.org/gruf/go-runners v1.6.1/go.mod h1:QRcSExqXX8DM0rm8Xs6qX7baOzyvw0JIe4mu3TsQT+Y= codeberg.org/gruf/go-sched v1.2.3 h1:H5ViDxxzOBR3uIyGBCf0eH8b1L8wMybOXcdtUUTXZHk= codeberg.org/gruf/go-sched v1.2.3/go.mod h1:vT9uB6KWFIIwnG9vcPY2a0alYNoqdL1mSzRM8I+PK7A= codeberg.org/gruf/go-store/v2 v2.2.1 h1:lbvMjhMLebefiaPNLtWvPySKSYM5xN1aztSxxz+vCzU= diff --git a/vendor/codeberg.org/gruf/go-runners/process.go b/vendor/codeberg.org/gruf/go-runners/process.go index 908e6edc..ca39ac0d 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() }() diff --git a/vendor/modules.txt b/vendor/modules.txt index 883b1fa9..9ba01b01 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -58,7 +58,7 @@ codeberg.org/gruf/go-mutexes # codeberg.org/gruf/go-pools v1.1.0 ## explicit; go 1.16 codeberg.org/gruf/go-pools -# codeberg.org/gruf/go-runners v1.6.0 +# codeberg.org/gruf/go-runners v1.6.1 ## explicit; go 1.19 codeberg.org/gruf/go-runners # codeberg.org/gruf/go-sched v1.2.3