Further improvements to make race conditions less likely.

v0.10
Martin Dosch 2 months ago
parent 46ed540910
commit 09693ba1bf
No known key found for this signature in database
GPG Key ID: 52A57CFCE13D657D

@ -1,6 +1,9 @@
# Changelog
## UNRELEASED
### Changed
- Fixed a race condition in receiving stanzas.
### Added
- Add a warning when run by the user *root*.

@ -18,6 +18,7 @@ import (
osUser "os/user"
"runtime"
"strings"
"sync"
"time"
"github.com/ProtonMail/gopenpgp/v2/crypto" // MIT License
@ -33,8 +34,11 @@ type configuration struct {
alias string
}
var mutex sync.Mutex
func closeAndExit(client *xmpp.Client, cancel context.CancelFunc, err error) {
cancel()
mutex.Lock()
client.Close()
if err != nil {
log.Fatal(err)

@ -54,13 +54,16 @@ func rcvStanzas(client *xmpp.Client, iqc chan xmpp.IQ, msgc chan xmpp.Chat, ctx
return
default:
go func() {
mutex.Lock()
received, err = client.Recv()
r <- received
}()
select {
case <-ctx.Done():
mutex.Unlock()
return
case <-r:
mutex.Unlock()
}
}
// Don't print errors if the program is getting shut down,

Loading…
Cancel
Save