From 602d10e372ab82fee11fb2e75505177d65b6f336 Mon Sep 17 00:00:00 2001 From: "Iskander (Alex) Sharipov" Date: Tue, 11 Dec 2018 02:28:13 +0300 Subject: [PATCH] proxy: fix case order in a type switch Type switch executes its clauses sequentially until the first match. The `*tcpmux.Stream` type implements `net.Conn`, so if `net.Conn` goes before `*tcpmux.Stream` case, it will catch `*tcpmux.Stream` values and will never let `case `*tcpmux.Stream` to execute. The solution is simple, move specific type case before the interface it implements. Found using gocritic linter, `caseOrder` checker. --- proxy/io.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/proxy/io.go b/proxy/io.go index feb82fc..1905de7 100644 --- a/proxy/io.go +++ b/proxy/io.go @@ -128,11 +128,11 @@ REPEAT: goto REPEAT case *udpBridgeConn: srcConn = src.(*udpBridgeConn) - case net.Conn: - srcConn = src.(net.Conn) case *tcpmux.Stream: // Stream has its own management of timeout return + case net.Conn: + srcConn = src.(net.Conn) default: return }