cmd/strelaysrv: Fix a few connection and routine leaks (fixes #4245)
GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4273
This commit is contained in:
parent
8e9119eedf
commit
94acc20dd6
@ -59,6 +59,13 @@ func listener(proto, addr string, config *tls.Config) {
|
|||||||
|
|
||||||
func protocolConnectionHandler(tcpConn net.Conn, config *tls.Config) {
|
func protocolConnectionHandler(tcpConn net.Conn, config *tls.Config) {
|
||||||
conn := tls.Server(tcpConn, 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()
|
err := conn.Handshake()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if debug {
|
if debug {
|
||||||
@ -81,6 +88,7 @@ func protocolConnectionHandler(tcpConn net.Conn, config *tls.Config) {
|
|||||||
conn.Close()
|
conn.Close()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
conn.SetDeadline(time.Time{})
|
||||||
|
|
||||||
id := syncthingprotocol.NewDeviceID(certs[0].Raw)
|
id := syncthingprotocol.NewDeviceID(certs[0].Raw)
|
||||||
|
|
||||||
@ -277,6 +285,7 @@ func sessionConnectionHandler(conn net.Conn) {
|
|||||||
if debug {
|
if debug {
|
||||||
log.Println("Weird error setting deadline:", err, "on", conn.RemoteAddr())
|
log.Println("Weird error setting deadline:", err, "on", conn.RemoteAddr())
|
||||||
}
|
}
|
||||||
|
conn.Close()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -16,8 +16,16 @@ var rc *rateCalculator
|
|||||||
func statusService(addr string) {
|
func statusService(addr string) {
|
||||||
rc = newRateCalculator(360, 10*time.Second, &bytesProxied)
|
rc = newRateCalculator(360, 10*time.Second, &bytesProxied)
|
||||||
|
|
||||||
http.HandleFunc("/status", getStatus)
|
handler := http.NewServeMux()
|
||||||
if err := http.ListenAndServe(addr, nil); err != nil {
|
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)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user