Просмотр исходного кода

Don't log an error when SetClosedSignal is called on a closed conn

Rod Hynes 11 лет назад
Родитель
Сommit
f08aa6066f
4 измененных файлов с 16 добавлено и 12 удалено
  1. 5 4
      psiphon/TCPConn.go
  2. 2 2
      psiphon/conn.go
  3. 3 3
      psiphon/meekConn.go
  4. 6 3
      psiphon/tunnel.go

+ 5 - 4
psiphon/TCPConn.go

@@ -61,15 +61,16 @@ func DialTCP(addr string, config *DialConfig) (conn *TCPConn, err error) {
 	return conn, nil
 	return conn, nil
 }
 }
 
 
-// SetClosedSignal implements psiphon.Conn.SetClosedSignal
-func (conn *TCPConn) SetClosedSignal(closedSignal chan struct{}) (err error) {
+// SetClosedSignal implements psiphon.Conn.SetClosedSignal. Returns true
+// if signal is successfully set, or false if the conn is already closed.
+func (conn *TCPConn) SetClosedSignal(closedSignal chan struct{}) bool {
 	conn.mutex.Lock()
 	conn.mutex.Lock()
 	defer conn.mutex.Unlock()
 	defer conn.mutex.Unlock()
 	if conn.isClosed {
 	if conn.isClosed {
-		return ContextError(errors.New("connection is already closed"))
+		return false
 	}
 	}
 	conn.closedSignal = closedSignal
 	conn.closedSignal = closedSignal
-	return nil
+	return true
 }
 }
 
 
 // Close terminates a connected (net.Conn) or connecting (socketFd) TCPConn.
 // Close terminates a connected (net.Conn) or connecting (socketFd) TCPConn.

+ 2 - 2
psiphon/conn.go

@@ -77,11 +77,11 @@ type Conn interface {
 	net.Conn
 	net.Conn
 
 
 	// SetClosedSignal sets the channel which will be signaled
 	// SetClosedSignal sets the channel which will be signaled
-	// when the connection is closed. This function returns an error
+	// when the connection is closed. This function returns false
 	// if the connection is already closed (and would never send
 	// if the connection is already closed (and would never send
 	// the signal). SetClosedSignal and Close may be called by
 	// the signal). SetClosedSignal and Close may be called by
 	// concurrent goroutines.
 	// concurrent goroutines.
-	SetClosedSignal(closedSignal chan struct{}) (err error)
+	SetClosedSignal(closedSignal chan struct{}) bool
 }
 }
 
 
 // Conns is a synchronized list of Conns that is used to coordinate
 // Conns is a synchronized list of Conns that is used to coordinate

+ 3 - 3
psiphon/meekConn.go

@@ -187,14 +187,14 @@ func DialMeek(
 }
 }
 
 
 // SetClosedSignal implements psiphon.Conn.SetClosedSignal
 // SetClosedSignal implements psiphon.Conn.SetClosedSignal
-func (meek *MeekConn) SetClosedSignal(closedSignal chan struct{}) (err error) {
+func (meek *MeekConn) SetClosedSignal(closedSignal chan struct{}) bool {
 	meek.mutex.Lock()
 	meek.mutex.Lock()
 	defer meek.mutex.Unlock()
 	defer meek.mutex.Unlock()
 	if meek.isClosed {
 	if meek.isClosed {
-		return ContextError(errors.New("connection is already closed"))
+		return false
 	}
 	}
 	meek.closedSignal = closedSignal
 	meek.closedSignal = closedSignal
-	return nil
+	return true
 }
 }
 
 
 // Close terminates the meek connection. Close waits for the relay processing goroutine
 // Close terminates the meek connection. Close waits for the relay processing goroutine

+ 6 - 3
psiphon/tunnel.go

@@ -344,11 +344,14 @@ func (tunnel *Tunnel) operateTunnel(config *Config, tunnelOwner TunnelOwner) {
 	defer sshKeepAliveTicker.Stop()
 	defer sshKeepAliveTicker.Stop()
 
 
 	tunnelClosedSignal := make(chan struct{}, 1)
 	tunnelClosedSignal := make(chan struct{}, 1)
-	err := tunnel.conn.SetClosedSignal(tunnelClosedSignal)
-	if err != nil {
-		err = fmt.Errorf("failed to set closed signal: %s", err)
+	if !tunnel.conn.SetClosedSignal(tunnelClosedSignal) {
+		// Tunnel is already closed. This is not unexpected -- for example,
+		// when establish is interrupted.
+		Notice(NOTICE_INFO, "shutdown operate tunnel (tunnel already closed)")
+		return
 	}
 	}
 
 
+	var err error
 	for err == nil {
 	for err == nil {
 		select {
 		select {
 		case <-statsTimer.C:
 		case <-statsTimer.C: