Browse Source

fix a race condition handling new proxy connections by passing the connection variable into the goroutine instead of closing over it

Alan Shreve 12 years ago
parent
commit
d2f3fc8440
1 changed files with 3 additions and 3 deletions
  1. 3 3
      src/ngrok/server/main.go

+ 3 - 3
src/ngrok/server/main.go

@@ -78,8 +78,8 @@ func proxyListener(addr *net.TCPAddr, domain string) {
 	// set global proxy addr variable
 	// set global proxy addr variable
 	proxyAddr = fmt.Sprintf("%s:%d", domain, listener.Port)
 	proxyAddr = fmt.Sprintf("%s:%d", domain, listener.Port)
 	log.Info("Listening for proxy connection on %d", listener.Port)
 	log.Info("Listening for proxy connection on %d", listener.Port)
-	for conn := range listener.Conns {
-		go func() {
+	for proxyConn := range listener.Conns {
+		go func(conn conn.Conn) {
 			// fail gracefully if the proxy connection dies
 			// fail gracefully if the proxy connection dies
 			defer func() {
 			defer func() {
 				if r := recover(); r != nil {
 				if r := recover(); r != nil {
@@ -103,7 +103,7 @@ func proxyListener(addr *net.TCPAddr, domain string) {
 
 
 			// register the proxy connection with the tunnel
 			// register the proxy connection with the tunnel
 			tunnel.RegisterProxy(conn)
 			tunnel.RegisterProxy(conn)
-		}()
+		}(proxyConn)
 	}
 	}
 }
 }