[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [flashproxy/master] Add a timeout for reading HTTP requests after connect.



commit e201fabb944dd77a21913cbcc26dcb9dd262fcd9
Author: David Fifield <david@xxxxxxxxxxxxxxx>
Date:   Fri Apr 19 18:03:21 2013 -0700

    Add a timeout for reading HTTP requests after connect.
    
    This is a try at fixing #8626, "too many open files." Before this, a
    client could just connect to the port and wait forever before sending
    the WebSocket request, using up a descriptor.
    
    Once the WebSocket handshake is completed, you can still keep the socket
    open forever, but that's more like intended behavior.
---
 ChangeLog                               |    2 ++
 websocket-transport/websocket-server.go |   11 +++++++++--
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 3c24a31..e0c11db 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,8 @@ Changes in version 1.0
   o Fixed badge rendering for a certain combination of Chrome and
     AdBlock Plus. Patch by Arlo Breault. Fixes bug 8300.
 
+  o There is now a 10-second HTTP request timeout in websocket-server.
+
 Changes in version 0.12
   o The new flashproxy-reg-url program prints a URL which, when
     requested, causes an address to be registered with the facilitator.
diff --git a/websocket-transport/websocket-server.go b/websocket-transport/websocket-server.go
index aa4fe57..1abff87 100644
--- a/websocket-transport/websocket-server.go
+++ b/websocket-transport/websocket-server.go
@@ -19,6 +19,8 @@ import (
 	"time"
 )
 
+const requestTimeout = 10 * time.Second
+
 var logFile = os.Stderr
 
 var ptInfo PtServerInfo
@@ -157,6 +159,8 @@ func proxy(local *net.TCPConn, conn *websocketConn) {
 }
 
 func websocketHandler(ws *Websocket) {
+	// Undo timeouts on HTTP request handling.
+	ws.Conn.SetDeadline(time.Time{})
 	conn := NewWebsocketConn(ws)
 
 	handlerChan <- 1
@@ -183,8 +187,11 @@ func startListener(addr *net.TCPAddr) (*net.TCPListener, error) {
 		config.Subprotocols = []string{"base64"}
 		// 16 kilobytes, possibly base64-encoded.
 		config.MaxMessageSize = 16*1024*4/3 + 1
-		http.Handle("/", config.Handler(websocketHandler))
-		err = http.Serve(ln, nil)
+		s := &http.Server{
+			Handler:     config.Handler(websocketHandler),
+			ReadTimeout: requestTimeout,
+		}
+		err = s.Serve(ln)
 		if err != nil {
 			Log("http.Serve: " + err.Error())
 		}

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