From b5d5907d696d4b0d8e1cbf5201efe227bfb73a02 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Tue, 22 Sep 2020 09:56:58 +0100 Subject: [PATCH] Synchronous perform-join as long as possible --- federationsender/internal/perform.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/federationsender/internal/perform.go b/federationsender/internal/perform.go index b3264c4de..f9d07e887 100644 --- a/federationsender/internal/perform.go +++ b/federationsender/internal/perform.go @@ -186,8 +186,15 @@ func (r *FederationSenderInternalAPI) performJoinUsingServer( } r.statistics.ForServer(serverName).Success() + // Process the join response in a goroutine. The idea here is + // that we'll try and wait for as long as possible for the work + // to complete, but if the client does give up waiting, we'll + // still continue to process the join anyway so that we don't + // waste the effort. + var cancel context.CancelFunc + ctx, cancel = context.WithCancel(context.Background()) go func() { - ctx = context.Background() + defer cancel() // Check that the send_join response was valid. joinCtx := perform.JoinContext(r.federation, r.keyRing) @@ -219,6 +226,7 @@ func (r *FederationSenderInternalAPI) performJoinUsingServer( } }() + <-ctx.Done() return nil }