Browse Source

Upgrade Tapir - Fix 2 small memory leaks around outbound connection handling

tapir-gc
Sarah Jamie Lewis 2 months ago
parent
commit
cade5f7793
  1. 2
      go.mod
  2. 2
      go.sum
  3. 23
      protocol/connections/engine.go
  4. 1
      protocol/connections/tokenboardclientapp.go

2
go.mod

@ -3,7 +3,7 @@ module cwtch.im/cwtch
go 1.14
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/log v1.0.3
github.com/gtank/ristretto255 v0.1.2

2
go.sum

@ -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.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.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/go.mod h1:13ZqhKyqakDsN/ZkQkIGNULsmLyqtXc46XBcnuXm/mU=
git.openprivacy.ca/openprivacy/connectivity v1.8.3 h1:bWM8aQHqHIpobYQcLQ9OsNPoIl+H+4JFWbYGdG0nHlg=

23
protocol/connections/engine.go

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

1
protocol/connections/tokenboardclientapp.go

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

Loading…
Cancel
Save