mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-09 14:50:56 +00:00
Don't take down HTTP(S) server on connection errors (fixes #700)
This commit is contained in:
parent
97844603fc
commit
45af549897
@ -96,8 +96,9 @@ func (l *DowngradingListener) Accept() (net.Conn, error) {
|
||||
br := bufio.NewReader(conn)
|
||||
bs, err := br.Peek(1)
|
||||
if err != nil {
|
||||
conn.Close()
|
||||
return nil, err
|
||||
// We hit a read error here, but the Accept() call succeeded so we must not return an error.
|
||||
// We return the connection as is and let whoever tries to use it deal with the error.
|
||||
return conn, nil
|
||||
}
|
||||
|
||||
wrapper := &WrappedConnection{br, conn}
|
||||
|
@ -33,6 +33,7 @@ var env = []string{
|
||||
"HOME=.",
|
||||
"STTRACE=model",
|
||||
"STGUIAPIKEY=" + apiKey,
|
||||
"STNORESTART=1",
|
||||
}
|
||||
|
||||
type syncthingProcess struct {
|
||||
|
@ -12,8 +12,8 @@ import (
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
@ -26,8 +26,6 @@ func TestStressHTTP(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
os.Setenv("STNORESTART", "1")
|
||||
|
||||
log.Println("Starting up...")
|
||||
sender := syncthingProcess{ // id1
|
||||
log: "2.out",
|
||||
@ -56,6 +54,23 @@ func TestStressHTTP(t *testing.T) {
|
||||
var lock sync.Mutex
|
||||
|
||||
errChan := make(chan error, 2)
|
||||
|
||||
// One thread with immediately closed connections
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
for time.Since(t0).Seconds() < 30 {
|
||||
conn, err := net.Dial("tcp", "localhost:8082")
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
errChan <- err
|
||||
return
|
||||
}
|
||||
conn.Close()
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
// 50 threads doing HTTP and HTTPS requests
|
||||
for i := 0; i < 50; i++ {
|
||||
i := i
|
||||
wg.Add(1)
|
||||
|
Loading…
Reference in New Issue
Block a user