diff --git a/app/commander/commander.go b/app/commander/commander.go index fef554953..a60db17ea 100644 --- a/app/commander/commander.go +++ b/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. diff --git a/app/commander/outbound.go b/app/commander/outbound.go index 25e476db1..99ed49bd9 100644 --- a/app/commander/outbound.go +++ b/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 } diff --git a/common/common.go b/common/common.go index 2f58ba7f2..82524b8f7 100644 --- a/common/common.go +++ b/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) {}