Darien Raymond 7 anni fa
parent
commit
f175d322ae
3 ha cambiato i file con 12 aggiunte e 6 eliminazioni
  1. 5 3
      app/commander/commander.go
  2. 4 3
      app/commander/outbound.go
  3. 3 0
      common/common.go

+ 5 - 3
app/commander/commander.go

@@ -73,12 +73,14 @@ func (c *Commander) Start() error {
 		}
 	}()
 
-	c.ohm.RemoveHandler(context.Background(), c.config.Tag)
-	c.ohm.AddHandler(context.Background(), &Outbound{
+	if err := c.ohm.RemoveHandler(context.Background(), c.config.Tag); err != nil {
+		newError("failed to remove existing handler").WriteToLog()
+	}
+
+	return c.ohm.AddHandler(context.Background(), &Outbound{
 		tag:      c.config.Tag,
 		listener: listener,
 	})
-	return nil
 }
 
 // Close implements common.Closable.

+ 4 - 3
app/commander/outbound.go

@@ -10,6 +10,7 @@ import (
 	"v2ray.com/core/transport/ray"
 )
 
+// OutboundListener is a net.Listener for listening gRPC connections.
 type OutboundListener struct {
 	buffer chan net.Conn
 	done   *signal.Done
@@ -19,9 +20,9 @@ func (l *OutboundListener) add(conn net.Conn) {
 	select {
 	case l.buffer <- conn:
 	case <-l.done.C():
-		conn.Close()
+		common.Ignore(conn.Close(), "We can do nothing if Close() returns error.")
 	default:
-		conn.Close()
+		common.Ignore(conn.Close(), "We can do nothing if Close() returns error.")
 	}
 }
 
@@ -42,7 +43,7 @@ L:
 	for {
 		select {
 		case c := <-l.buffer:
-			c.Close()
+			common.Ignore(c.Close(), "We can do nothing if errored.")
 		default:
 			break L
 		}

+ 3 - 0
common/common.go

@@ -21,3 +21,6 @@ func Must2(v interface{}, err error) interface{} {
 func Error2(v interface{}, err error) error {
 	return err
 }
+
+// Ignore an error with reason, for lint purpose.
+func Ignore(err error, reason string) {}