mirror of
https://github.com/XRPLF/clio.git
synced 2025-11-19 19:25:53 +00:00
fix: Data race in new webserver (#1926)
There was a data race inside `CoroutineGroup` because internal timer was used from multiple threads in the methods `asyncWait()` and `onCoroutineComplete()`. Changing `registerForeign()` to spawn to the same `yield_context` fixes the problem because now the timer is accessed only from the same coroutine which has an internal strand. During debugging I also added websocket support for `request_gun` tool.
This commit is contained in:
@@ -3,6 +3,7 @@ package ammo_provider
|
||||
import (
|
||||
"bufio"
|
||||
"io"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
@@ -12,17 +13,17 @@ type AmmoProvider struct {
|
||||
}
|
||||
|
||||
func (ap *AmmoProvider) getIndex() uint64 {
|
||||
if ap.currentBullet.Load() >= uint64(len(ap.ammo)) {
|
||||
ap.currentBullet.Store(1)
|
||||
return 0
|
||||
}
|
||||
result := ap.currentBullet.Load()
|
||||
ap.currentBullet.Add(1)
|
||||
return result
|
||||
result := ap.currentBullet.Add(1)
|
||||
return result % uint64(len(ap.ammo))
|
||||
}
|
||||
|
||||
func (ap *AmmoProvider) GetBullet() string {
|
||||
return ap.ammo[ap.getIndex()]
|
||||
for {
|
||||
res := ap.ammo[ap.getIndex()]
|
||||
if !strings.HasPrefix(res, "#") {
|
||||
return res
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func New(reader io.Reader) *AmmoProvider {
|
||||
|
||||
Reference in New Issue
Block a user