Commit 995821d3 authored by Jeromy's avatar Jeromy

be more careful about holding onto things forever

parent d26dd414
...@@ -82,7 +82,6 @@ func (s *secureSession) RemotePublicKey() ci.PubKey { ...@@ -82,7 +82,6 @@ func (s *secureSession) RemotePublicKey() ci.PubKey {
// Close closes the secure session // Close closes the secure session
func (s *secureSession) Close() error { func (s *secureSession) Close() error {
s.cancel()
s.handshakeMu.Lock() s.handshakeMu.Lock()
defer s.handshakeMu.Unlock() defer s.handshakeMu.Unlock()
if s.secure == nil { if s.secure == nil {
......
...@@ -42,7 +42,6 @@ const nonceSize = 16 ...@@ -42,7 +42,6 @@ const nonceSize = 16
// and decrypting traffic from an insecure channel. // and decrypting traffic from an insecure channel.
type secureSession struct { type secureSession struct {
ctx context.Context ctx context.Context
cancel context.CancelFunc
secure msgio.ReadWriteCloser secure msgio.ReadWriteCloser
insecure io.ReadWriteCloser insecure io.ReadWriteCloser
...@@ -72,7 +71,6 @@ func (s *secureSession) Loggable() map[string]interface{} { ...@@ -72,7 +71,6 @@ func (s *secureSession) Loggable() map[string]interface{} {
func newSecureSession(ctx context.Context, local peer.ID, key ci.PrivKey, insecure io.ReadWriteCloser) (*secureSession, error) { func newSecureSession(ctx context.Context, local peer.ID, key ci.PrivKey, insecure io.ReadWriteCloser) (*secureSession, error) {
s := &secureSession{localPeer: local, localKey: key} s := &secureSession{localPeer: local, localKey: key}
s.ctx, s.cancel = context.WithCancel(ctx)
switch { switch {
case s.localPeer == "": case s.localPeer == "":
...@@ -110,6 +108,7 @@ func (s *secureSession) Handshake() error { ...@@ -110,6 +108,7 @@ func (s *secureSession) Handshake() error {
// keys, IDs, and initiate communication, assigning all necessary params. // keys, IDs, and initiate communication, assigning all necessary params.
// requires the duplex channel to be a msgio.ReadWriter (for framed messaging) // requires the duplex channel to be a msgio.ReadWriter (for framed messaging)
func (s *secureSession) runHandshake() error { func (s *secureSession) runHandshake() error {
defer func() { s.ctx = nil }() // clear to save memory
ctx, cancel := context.WithTimeout(s.ctx, HandshakeTimeout) // remove ctx, cancel := context.WithTimeout(s.ctx, HandshakeTimeout) // remove
defer cancel() defer cancel()
......
...@@ -82,4 +82,6 @@ func TestBasicETMStream(t *testing.T) { ...@@ -82,4 +82,6 @@ func TestBasicETMStream(t *testing.T) {
if string(before) != string(msg) { if string(before) != string(msg) {
t.Fatal("got wrong message") t.Fatal("got wrong message")
} }
r.Close()
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment