Browse Source

Fix: post-reconnect relaying issues

- setting new channel in UseNewTunnel didn't
  interrupt blocking Read calls
- tun.Client relay routines aborted on
  temporary error conditions instead of
  continuing
Rod Hynes 8 years ago
parent
commit
db1ba796ba
2 changed files with 13 additions and 8 deletions
  1. 6 6
      psiphon/common/tun/tun.go
  2. 7 2
      psiphon/packetTunnelTransport.go

+ 6 - 6
psiphon/common/tun/tun.go

@@ -1417,9 +1417,9 @@ func (client *Client) Start() {
 			if err != nil {
 				client.config.Logger.WithContextFields(
 					common.LogFields{"error": err}).Info("write channel packets failed")
-				// Only this goroutine exits and no alarm is raised. It's assumed
-				// that if the channel fails, the outer client will know about it.
-				return
+				// May be temporary error condition, such as reconnecting the tunnel;
+				// keep working. The packets are most likely dropped.
+				continue
 			}
 		}
 	}()
@@ -1440,9 +1440,9 @@ func (client *Client) Start() {
 			if err != nil {
 				client.config.Logger.WithContextFields(
 					common.LogFields{"error": err}).Info("read channel packet failed")
-				// Only this goroutine exits and no alarm is raised. It's assumed
-				// that if the channel fails, the outer client will know about it.
-				return
+				// May be temporary error condition, such as reconnecting the tunnel;
+				// keep working.
+				continue
 			}
 
 			if !processPacket(

+ 7 - 2
psiphon/packetTunnelTransport.go

@@ -111,7 +111,7 @@ func (p *PacketTunnelTransport) Read(data []byte) (int, error) {
 		p.failedChannel(channelConn, channelTunnel)
 	}
 
-	return n, err
+	return n, common.ContextError(err)
 }
 
 // Write implements the io.Writer interface. It uses the current transport channel
@@ -146,7 +146,7 @@ func (p *PacketTunnelTransport) Write(data []byte) (int, error) {
 		p.failedChannel(channelConn, channelTunnel)
 	}
 
-	return n, err
+	return n, common.ContextError(err)
 }
 
 // Close implements the io.Closer interface. Any underlying transport channel is
@@ -216,6 +216,11 @@ func (p *PacketTunnelTransport) setChannel(
 	default:
 	}
 
+	// Interrupt Read/Write calls blocking on any previous channel.
+	if p.channelConn != nil {
+		p.channelConn.Close()
+	}
+
 	p.channelConn = channelConn
 	p.channelTunnel = channelTunnel