From 9b18bef47af90b4d3e12bb4692afcf0ee61dd14f Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Wed, 16 Jun 2021 08:58:53 -0700 Subject: [PATCH 1/2] add mutex on StartCwtch and ReconnectCwtchForeground --- lib.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib.go b/lib.go index fa98476..5727865 100644 --- a/lib.go +++ b/lib.go @@ -15,6 +15,7 @@ import ( "git.openprivacy.ca/openprivacy/connectivity" "runtime" "strings" + "sync" "encoding/json" "fmt" @@ -42,6 +43,7 @@ var eventHandler *utils.EventHandler var acnQueue event.Queue var contactEventsQueue event.Queue var globalACN connectivity.ACN +var startLock sync.Mutex // ChatMessage API currently not officially documented, see // https://git.openprivacy.ca/cwtch.im/secure-development-handbook/issues/3 @@ -87,6 +89,8 @@ func StartCwtch(appDir string, torPath string) int { } func _startCwtch(appDir string, torPath string) { + startLock.Lock() + defer startLock.Unlock() // Exclude Tapir wire Messages (We need a TRACE level) log.ExcludeFromPattern("service.go") @@ -161,10 +165,13 @@ func c_ReconnectCwtchForeground() { // Like StartCwtch, but StartCwtch has already been called so we don't need to restart Tor etc (probably) // Do need to re-send initial state tho, eg profiles that are already loaded func ReconnectCwtchForeground() { + startLock.Lock() + defer startLock.Unlock() peerList := application.ListPeers() for onion := range peerList { eventHandler.Push(event.NewEvent(event.NewPeer, map[event.Field]string{event.Identity: onion, event.Created: event.False})) } + application.GetPrimaryBus().Publish(event.NewEvent(utils.CwtchStarted, map[event.Field]string{})) } //export c_SendAppEvent -- 2.25.1 From 11f09c95d24796b38d613a0490aad9514d3c06d0 Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Wed, 16 Jun 2021 11:41:36 -0700 Subject: [PATCH 2/2] remove mutex 'fix', instead just don't reconnect, assume whole stale thread and abandon --- lib.go | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/lib.go b/lib.go index 5727865..291c991 100644 --- a/lib.go +++ b/lib.go @@ -10,17 +10,15 @@ import ( "cwtch.im/cwtch/model" "cwtch.im/cwtch/model/attr" "cwtch.im/cwtch/peer" - contact "git.openprivacy.ca/flutter/libcwtch-go/features/contacts" - "git.openprivacy.ca/flutter/libcwtch-go/features/groups" - "git.openprivacy.ca/openprivacy/connectivity" - "runtime" - "strings" - "sync" - "encoding/json" "fmt" "git.openprivacy.ca/flutter/libcwtch-go/constants" + contact "git.openprivacy.ca/flutter/libcwtch-go/features/contacts" + "git.openprivacy.ca/flutter/libcwtch-go/features/groups" "git.openprivacy.ca/flutter/libcwtch-go/utils" + "git.openprivacy.ca/openprivacy/connectivity" + "runtime" + "strings" "encoding/base64" "git.openprivacy.ca/openprivacy/connectivity/tor" @@ -43,7 +41,6 @@ var eventHandler *utils.EventHandler var acnQueue event.Queue var contactEventsQueue event.Queue var globalACN connectivity.ACN -var startLock sync.Mutex // ChatMessage API currently not officially documented, see // https://git.openprivacy.ca/cwtch.im/secure-development-handbook/issues/3 @@ -89,8 +86,6 @@ func StartCwtch(appDir string, torPath string) int { } func _startCwtch(appDir string, torPath string) { - startLock.Lock() - defer startLock.Unlock() // Exclude Tapir wire Messages (We need a TRACE level) log.ExcludeFromPattern("service.go") @@ -165,8 +160,10 @@ func c_ReconnectCwtchForeground() { // Like StartCwtch, but StartCwtch has already been called so we don't need to restart Tor etc (probably) // Do need to re-send initial state tho, eg profiles that are already loaded func ReconnectCwtchForeground() { - startLock.Lock() - defer startLock.Unlock() + if application == nil { + log.Errorf("ReconnectCwtchForeground: Application is nil, presuming stale thread, EXITING Reconnect\n") + return + } peerList := application.ListPeers() for onion := range peerList { eventHandler.Push(event.NewEvent(event.NewPeer, map[event.Field]string{event.Identity: onion, event.Created: event.False})) -- 2.25.1