Closed xgess closed 5 years ago
Does the race coincide with the bot trying to send messages? You could try this, don't know if it's what's causing the wallet issue in particular.
"io"
"os/exec"
"strings"
+ "sync"
"time"
)
@@ -17,6 +18,7 @@ type API struct {
input io.Writer
username string
runOpts RunOptions
+ sync.Mutex
}
func getUsername(runOpts RunOptions) (username string, err error) {
@@ -168,20 +170,32 @@ type sendMessageArg struct {
Params sendMessageParams
}
-func (a *API) doSend(arg sendMessageArg) error {
+func (a *API) doSend(arg sendMessageArg) (*SendMessageResponse, error) {
+ a.Lock()
+ defer a.Unlock()
+
@heronhaye took your suggestion (saw another race). there was already a lock, so i kinda just moved around where it was used so that it would actually lock the pipes while they're in use.
i've been seeing some racey behavior in my bot. sometimes payment events don't get put into the channel if other things are happening at the same time.
a little bit of research led me to this: https://github.com/golang/go/issues/19685
@mmaxim what do you think? i was surprised it would help, but it does seem (at least locally) to have improved the situation. hard to know for sure since it's a pretty sporadic problem.