commit c7541223c704f76cb45a4e20bd20d963ea8d1fc7
Author: David Fifield <da...@bamsoftware.com>
Date:   Wed Jan 16 22:52:51 2019 -0700

    Don't wait for handlers to finish after SIGTERM.
    
    The requirement to wait until handlers are finished, as well as the
    complicated signal counting logic, was removed from pt-spec.txt in 2014.
    
    https://bugs.torproject.org/26389
    
    Compare
    
https://gitweb.torproject.org/pluggable-transports/goptlib.git/commit/?id=15f83653abbcced9003c96cc14edc5b2f82e0e0e
---
 meek-client/meek-client.go | 27 +++------------------------
 meek-server/meek-server.go | 25 ++-----------------------
 2 files changed, 5 insertions(+), 47 deletions(-)

diff --git a/meek-client/meek-client.go b/meek-client/meek-client.go
index 1b13f11..6059947 100644
--- a/meek-client/meek-client.go
+++ b/meek-client/meek-client.go
@@ -102,10 +102,6 @@ var options struct {
        UseHelper bool
 }
 
-// When a connection handler starts, +1 is written to this channel; when it
-// ends, -1 is written.
-var handlerChan = make(chan int)
-
 // RequestInfo encapsulates all the configuration used for a request–response
 // roundtrip, including variables that may come from SOCKS args or from the
 // command line.
@@ -279,11 +275,6 @@ func genSessionID() string {
 
 // Callback for new SOCKS requests.
 func handler(conn *pt.SocksConn) error {
-       handlerChan <- 1
-       defer func() {
-               handlerChan <- -1
-       }()
-
        defer conn.Close()
        err := conn.Grant(&net.TCPAddr{IP: net.IPv4zero, Port: 0})
        if err != nil {
@@ -473,8 +464,6 @@ func main() {
        }
        pt.CmethodsDone()
 
-       var numHandlers int = 0
-       var sig os.Signal
        sigChan := make(chan os.Signal, 1)
        signal.Notify(sigChan, syscall.SIGTERM)
 
@@ -488,23 +477,13 @@ func main() {
                }()
        }
 
-       // Keep track of handlers and wait for a signal.
-       sig = nil
-       for sig == nil {
-               select {
-               case n := <-handlerChan:
-                       numHandlers += n
-               case sig = <-sigChan:
-                       log.Printf("got signal %s", sig)
-               }
-       }
+       // Wait for a signal.
+       sig := <-sigChan
+       log.Printf("got signal %s", sig)
 
        for _, ln := range listeners {
                ln.Close()
        }
-       for numHandlers > 0 {
-               numHandlers += <-handlerChan
-       }
 
        log.Printf("done")
 }
diff --git a/meek-server/meek-server.go b/meek-server/meek-server.go
index 4676b47..42aab0a 100644
--- a/meek-server/meek-server.go
+++ b/meek-server/meek-server.go
@@ -70,10 +70,6 @@ const (
 
 var ptInfo pt.ServerInfo
 
-// When a connection handler starts, +1 is written to this channel; when it
-// ends, -1 is written.
-var handlerChan = make(chan int)
-
 func httpBadRequest(w http.ResponseWriter) {
        http.Error(w, "Bad request.", http.StatusBadRequest)
 }
@@ -115,11 +111,6 @@ func NewState() *State {
 }
 
 func (state *State) ServeHTTP(w http.ResponseWriter, req *http.Request) {
-       handlerChan <- 1
-       defer func() {
-               handlerChan <- -1
-       }()
-
        switch req.Method {
        case "GET":
                state.Get(w, req)
@@ -494,8 +485,6 @@ func main() {
        }
        pt.SmethodsDone()
 
-       var numHandlers int = 0
-       var sig os.Signal
        sigChan := make(chan os.Signal, 1)
        signal.Notify(sigChan, syscall.SIGTERM)
 
@@ -510,15 +499,8 @@ func main() {
        }
 
        // Keep track of handlers and wait for a signal.
-       sig = nil
-       for sig == nil {
-               select {
-               case n := <-handlerChan:
-                       numHandlers += n
-               case sig = <-sigChan:
-                       log.Printf("got signal %s", sig)
-               }
-       }
+       sig := <-sigChan
+       log.Printf("got signal %s", sig)
 
        /*
                // Not supported until go1.8.
@@ -526,9 +508,6 @@ func main() {
                        server.Close()
                }
        */
-       for numHandlers > 0 {
-               numHandlers += <-handlerChan
-       }
 
        log.Printf("done")
 }

_______________________________________________
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits

Reply via email to