Further improvements to make race conditions less likely.

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

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

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

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

Loading…
Cancel
Save