Skip to content

Commit

Permalink
cmd/strelaysrv: Fix a few connection and routine leaks (fixes syncthi…
Browse files Browse the repository at this point in the history
…ng#4245)

GitHub-Pull-Request: syncthing#4273
  • Loading branch information
AudriusButkevicius committed Jul 26, 2017
1 parent 8e9119e commit 94acc20
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
9 changes: 9 additions & 0 deletions cmd/strelaysrv/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ func listener(proto, addr string, config *tls.Config) {

func protocolConnectionHandler(tcpConn net.Conn, config *tls.Config) {
conn := tls.Server(tcpConn, config)
if err := conn.SetDeadline(time.Now().Add(messageTimeout)); err != nil {
if debug {
log.Println("Weird error setting deadline:", err, "on", conn.RemoteAddr())
}
conn.Close()
return
}
err := conn.Handshake()
if err != nil {
if debug {
Expand All @@ -81,6 +88,7 @@ func protocolConnectionHandler(tcpConn net.Conn, config *tls.Config) {
conn.Close()
return
}
conn.SetDeadline(time.Time{})

id := syncthingprotocol.NewDeviceID(certs[0].Raw)

Expand Down Expand Up @@ -277,6 +285,7 @@ func sessionConnectionHandler(conn net.Conn) {
if debug {
log.Println("Weird error setting deadline:", err, "on", conn.RemoteAddr())
}
conn.Close()
return
}

Expand Down
12 changes: 10 additions & 2 deletions cmd/strelaysrv/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,16 @@ var rc *rateCalculator
func statusService(addr string) {
rc = newRateCalculator(360, 10*time.Second, &bytesProxied)

http.HandleFunc("/status", getStatus)
if err := http.ListenAndServe(addr, nil); err != nil {
handler := http.NewServeMux()
handler.HandleFunc("/status", getStatus)

srv := http.Server{
Addr: addr,
Handler: handler,
ReadTimeout: 15 * time.Second,
}
srv.SetKeepAlivesEnabled(false)
if err := srv.ListenAndServe(); err != nil {
log.Fatal(err)
}
}
Expand Down

0 comments on commit 94acc20

Please sign in to comment.