Merge pull request 'Upgrade Tapir - Fix 2 small memory leaks around outbound connection handling' (#443) from tapir-gc into master
continuous-integration/drone/push Build is pending Details
continuous-integration/drone/tag Build is pending Details

Reviewed-on: #443
Reviewed-by: Dan Ballard <dan@openprivacy.ca>
This commit is contained in:
Sarah Jamie Lewis 2022-04-21 23:01:28 +00:00
commit bc38f4ec0a
4 changed files with 25 additions and 3 deletions

2
go.mod
View File

@ -3,7 +3,7 @@ module cwtch.im/cwtch
go 1.14 go 1.14
require ( require (
git.openprivacy.ca/cwtch.im/tapir v0.5.3 git.openprivacy.ca/cwtch.im/tapir v0.5.4
git.openprivacy.ca/openprivacy/connectivity v1.8.3 git.openprivacy.ca/openprivacy/connectivity v1.8.3
git.openprivacy.ca/openprivacy/log v1.0.3 git.openprivacy.ca/openprivacy/log v1.0.3
github.com/gtank/ristretto255 v0.1.2 github.com/gtank/ristretto255 v0.1.2

2
go.sum
View File

@ -4,6 +4,8 @@ git.openprivacy.ca/cwtch.im/tapir v0.5.2 h1:7qJlUGY8RZbI7905BzVEEVB0hxP2GzI3lGiP
git.openprivacy.ca/cwtch.im/tapir v0.5.2/go.mod h1:vVEu3CbXdyeMI5s1RkbROe1TBboNroGyJfODw8Ujlo8= git.openprivacy.ca/cwtch.im/tapir v0.5.2/go.mod h1:vVEu3CbXdyeMI5s1RkbROe1TBboNroGyJfODw8Ujlo8=
git.openprivacy.ca/cwtch.im/tapir v0.5.3 h1:ei01JCQTXV15IOP00o5hygQCKb3+yCibWGih7yQ5t94= git.openprivacy.ca/cwtch.im/tapir v0.5.3 h1:ei01JCQTXV15IOP00o5hygQCKb3+yCibWGih7yQ5t94=
git.openprivacy.ca/cwtch.im/tapir v0.5.3/go.mod h1:VJitTBzerc+WO53c5XY30P2JD2Nx9mgxuII1FBVwW8E= git.openprivacy.ca/cwtch.im/tapir v0.5.3/go.mod h1:VJitTBzerc+WO53c5XY30P2JD2Nx9mgxuII1FBVwW8E=
git.openprivacy.ca/cwtch.im/tapir v0.5.4 h1:CUcRVsM82Zx/pfcGqIviycavZcC50wXm67TiQ3mx6WY=
git.openprivacy.ca/cwtch.im/tapir v0.5.4/go.mod h1:VJitTBzerc+WO53c5XY30P2JD2Nx9mgxuII1FBVwW8E=
git.openprivacy.ca/openprivacy/bine v0.0.4 h1:CO7EkGyz+jegZ4ap8g5NWRuDHA/56KKvGySR6OBPW+c= git.openprivacy.ca/openprivacy/bine v0.0.4 h1:CO7EkGyz+jegZ4ap8g5NWRuDHA/56KKvGySR6OBPW+c=
git.openprivacy.ca/openprivacy/bine v0.0.4/go.mod h1:13ZqhKyqakDsN/ZkQkIGNULsmLyqtXc46XBcnuXm/mU= git.openprivacy.ca/openprivacy/bine v0.0.4/go.mod h1:13ZqhKyqakDsN/ZkQkIGNULsmLyqtXc46XBcnuXm/mU=
git.openprivacy.ca/openprivacy/connectivity v1.8.3 h1:bWM8aQHqHIpobYQcLQ9OsNPoIl+H+4JFWbYGdG0nHlg= git.openprivacy.ca/openprivacy/connectivity v1.8.3 h1:bWM8aQHqHIpobYQcLQ9OsNPoIl+H+4JFWbYGdG0nHlg=

View File

@ -5,6 +5,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"strconv" "strconv"
"strings"
"sync" "sync"
"time" "time"
@ -293,14 +294,18 @@ func (e *engine) Shutdown() {
defer e.ephemeralServicesLock.Unlock() defer e.ephemeralServicesLock.Unlock()
for _, connection := range e.ephemeralServices { for _, connection := range e.ephemeralServices {
log.Infof("shutting down ephemeral service") log.Infof("shutting down ephemeral service")
connection.connectingLock.Lock()
connection.service.Shutdown() connection.service.Shutdown()
connection.connectingLock.Unlock()
} }
e.queue.Shutdown() e.queue.Shutdown()
} }
// peerWithOnion is the entry point for cwtchPeer relationships // peerWithOnion is the entry point for cwtchPeer relationships
// needs to be run in a goroutine as will block on Open. // needs to be run in a goroutine as will block on Open.
func (e *engine) peerWithOnion(onion string) { func (e *engine) peerWithOnion(onion string) {
log.Debugf("Called PeerWithOnion for %v", onion) log.Debugf("Called PeerWithOnion for %v", onion)
if !e.isBlocked(onion) { if !e.isBlocked(onion) {
e.ignoreOnShutdown(e.peerConnecting)(onion) e.ignoreOnShutdown(e.peerConnecting)(onion)
@ -473,6 +478,15 @@ func (e *engine) peerAck(onion string, eventID string) {
func (e *engine) peerDisconnected(onion string) { func (e *engine) peerDisconnected(onion string) {
// Clean up any existing get value requests...
e.getValRequests.Range(func(key, value interface{}) bool {
keyString := key.(string)
if strings.HasPrefix(keyString, onion) {
e.getValRequests.Delete(keyString)
}
return true
})
// Purge circuit information... // Purge circuit information...
e.eventManager.Publish(event.NewEvent(event.ACNInfo, map[event.Field]string{ e.eventManager.Publish(event.NewEvent(event.ACNInfo, map[event.Field]string{
event.Handle: onion, event.Handle: onion,
@ -494,8 +508,13 @@ func (e *engine) sendGetValToPeer(eventID, onion, scope, path string) error {
return err return err
} }
e.getValRequests.Store(onion+eventID, message) key := onion + eventID
return e.sendPeerMessage(onion, pmodel.PeerMessage{ID: eventID, Context: event.ContextGetVal, Data: message}) e.getValRequests.Store(key, message)
err = e.sendPeerMessage(onion, pmodel.PeerMessage{ID: eventID, Context: event.ContextGetVal, Data: message})
if err != nil {
e.getValRequests.Delete(key)
}
return err
} }
func (e *engine) sendRetValToPeer(eventID, onion, val, existsStr string) error { func (e *engine) sendRetValToPeer(eventID, onion, val, existsStr string) error {

View File

@ -178,6 +178,7 @@ func (ta *TokenBoardClient) MakePayment() error {
id, sk := primitives.InitializeEphemeralIdentity() id, sk := primitives.InitializeEphemeralIdentity()
client := new(tor.BaseOnionService) client := new(tor.BaseOnionService)
client.Init(ta.acn, sk, &id) client.Init(ta.acn, sk, &id)
defer client.Shutdown()
tokenApplication := new(applications.TokenApplication) tokenApplication := new(applications.TokenApplication)
tokenApplication.TokenService = ta.tokenService tokenApplication.TokenService = ta.tokenService