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:
Sergey Kuznetsov
2025-02-27 15:08:46 +00:00
committed by GitHub
parent b909b8879d
commit d11e7bc60e
13 changed files with 116 additions and 32 deletions

View File

@@ -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 {