From c717f082879f6663b1e57a4e4eec0864a92736f0 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Wed, 24 May 2023 13:42:41 +0200 Subject: [PATCH] wip --- lib/connections/quic_dial.go | 11 +++++++++++ lib/connections/tcp_dial.go | 2 +- lib/model/indexhandler.go | 18 +++++++++--------- lib/model/model.go | 2 +- test/h1/config.xml | 2 +- 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/lib/connections/quic_dial.go b/lib/connections/quic_dial.go index 6c9a03670..696b94b6c 100644 --- a/lib/connections/quic_dial.go +++ b/lib/connections/quic_dial.go @@ -15,6 +15,7 @@ import ( "fmt" "net" "net/url" + "os" "time" "github.com/quic-go/quic-go" @@ -22,6 +23,7 @@ import ( "github.com/syncthing/syncthing/lib/config" "github.com/syncthing/syncthing/lib/connections/registry" "github.com/syncthing/syncthing/lib/protocol" + "github.com/syncthing/syncthing/lib/rand" ) const ( @@ -95,6 +97,15 @@ func (d *quicDialer) Dial(ctx context.Context, _ protocol.DeviceID, uri *url.URL if isLocal { priority = d.lanPriority } + + // XXX: Induced flakyness + if dur, _ := time.ParseDuration(os.Getenv("CONN_FLAKY_LIFETIME")); dur > 0 { + dur = dur/2 + time.Duration(rand.Intn(int(dur))) + time.AfterFunc(dur, func() { + stream.Close() + }) + } + return newInternalConn(&quicTlsConn{session, stream, createdConn}, connTypeQUICClient, isLocal, priority), nil } diff --git a/lib/connections/tcp_dial.go b/lib/connections/tcp_dial.go index e862c40a6..233f8ed0f 100644 --- a/lib/connections/tcp_dial.go +++ b/lib/connections/tcp_dial.go @@ -66,7 +66,7 @@ func (d *tcpDialer) Dial(ctx context.Context, _ protocol.DeviceID, uri *url.URL) } // XXX: Induced flakyness - if dur, _ := time.ParseDuration(os.Getenv("TCP_FLAKY_LIFETIME")); dur > 0 { + if dur, _ := time.ParseDuration(os.Getenv("CONN_FLAKY_LIFETIME")); dur > 0 { dur = dur/2 + time.Duration(rand.Intn(int(dur))) time.AfterFunc(dur, func() { tc.Close() diff --git a/lib/model/indexhandler.go b/lib/model/indexhandler.go index 8f6aab0ed..9212397d7 100644 --- a/lib/model/indexhandler.go +++ b/lib/model/indexhandler.go @@ -138,17 +138,17 @@ func (s *indexHandler) Serve(ctx context.Context) (err error) { close(stop) }() - ctx, cancel := context.WithCancel(ctx) + // ctx, cancel := context.WithCancel(ctx) // Cancel the context when the connection closes - go func() { - select { - case <-s.conn.Closed(): - cancel() - case <-ctx.Done(): - case <-stop: - } - }() + // go func() { + // select { + // case <-s.conn.Closed(): + // cancel() + // case <-ctx.Done(): + // case <-stop: + // } + // }() // Broadcast the pause cond when the context quits go func() { diff --git a/lib/model/model.go b/lib/model/model.go index 48f4d2efd..17a139b2b 100644 --- a/lib/model/model.go +++ b/lib/model/model.go @@ -2186,7 +2186,7 @@ func (m *model) Connection(deviceID protocol.DeviceID) (protocol.Connection, boo m.pmut.RLock() connID, ok := m.deviceConns[deviceID] if ok { - conn = m.conns[connID[0]] + conn, ok = m.conns[connID[0]] } m.pmut.RUnlock() if ok { diff --git a/test/h1/config.xml b/test/h1/config.xml index c735219f2..062a0c379 100644 --- a/test/h1/config.xml +++ b/test/h1/config.xml @@ -1,5 +1,5 @@ - + fake