mirror of
https://github.com/matrix-org/dendrite.git
synced 2024-11-26 08:11:55 -06:00
Use background contexts during federated join for clarity (#2134)
* Use background contexts for clarity * Don't wait for the context to expire before trying to return * Actually we don't really need a goroutine here
This commit is contained in:
parent
c773b038bb
commit
2a5c38fee2
|
@ -196,29 +196,22 @@ func (r *FederationInternalAPI) performJoinUsingServer(
|
||||||
return fmt.Errorf("respMakeJoin.JoinEvent.Build: %w", err)
|
return fmt.Errorf("respMakeJoin.JoinEvent.Build: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// No longer reuse the request context from this point forward.
|
|
||||||
// We don't want the client timing out to interrupt the join.
|
|
||||||
var cancel context.CancelFunc
|
|
||||||
ctx, cancel = context.WithCancel(context.Background())
|
|
||||||
|
|
||||||
// Try to perform a send_join using the newly built event.
|
// Try to perform a send_join using the newly built event.
|
||||||
respSendJoin, err := r.federation.SendJoin(
|
respSendJoin, err := r.federation.SendJoin(
|
||||||
ctx,
|
context.Background(),
|
||||||
serverName,
|
serverName,
|
||||||
event,
|
event,
|
||||||
respMakeJoin.RoomVersion,
|
respMakeJoin.RoomVersion,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.statistics.ForServer(serverName).Failure()
|
r.statistics.ForServer(serverName).Failure()
|
||||||
cancel()
|
|
||||||
return fmt.Errorf("r.federation.SendJoin: %w", err)
|
return fmt.Errorf("r.federation.SendJoin: %w", err)
|
||||||
}
|
}
|
||||||
r.statistics.ForServer(serverName).Success()
|
r.statistics.ForServer(serverName).Success()
|
||||||
|
|
||||||
// Sanity-check the join response to ensure that it has a create
|
// Sanity-check the join response to ensure that it has a create
|
||||||
// event, that the room version is known, etc.
|
// event, that the room version is known, etc.
|
||||||
if err := sanityCheckAuthChain(respSendJoin.AuthEvents); err != nil {
|
if err = sanityCheckAuthChain(respSendJoin.AuthEvents); err != nil {
|
||||||
cancel()
|
|
||||||
return fmt.Errorf("sanityCheckAuthChain: %w", err)
|
return fmt.Errorf("sanityCheckAuthChain: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,25 +220,25 @@ func (r *FederationInternalAPI) performJoinUsingServer(
|
||||||
// to complete, but if the client does give up waiting, we'll
|
// to complete, but if the client does give up waiting, we'll
|
||||||
// still continue to process the join anyway so that we don't
|
// still continue to process the join anyway so that we don't
|
||||||
// waste the effort.
|
// waste the effort.
|
||||||
go func() {
|
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
// TODO: Can we expand Check here to return a list of missing auth
|
// TODO: Can we expand Check here to return a list of missing auth
|
||||||
// events rather than failing one at a time?
|
// events rather than failing one at a time?
|
||||||
respState, err := respSendJoin.Check(ctx, r.keyRing, event, federatedAuthProvider(ctx, r.federation, r.keyRing, serverName))
|
var respState *gomatrixserverlib.RespState
|
||||||
|
respState, err = respSendJoin.Check(
|
||||||
|
context.Background(),
|
||||||
|
r.keyRing,
|
||||||
|
event,
|
||||||
|
federatedAuthProvider(ctx, r.federation, r.keyRing, serverName),
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithFields(logrus.Fields{
|
return fmt.Errorf("respSendJoin.Check: %w", err)
|
||||||
"room_id": roomID,
|
|
||||||
"user_id": userID,
|
|
||||||
}).WithError(err).Error("Failed to process room join response")
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we successfully performed a send_join above then the other
|
// If we successfully performed a send_join above then the other
|
||||||
// server now thinks we're a part of the room. Send the newly
|
// server now thinks we're a part of the room. Send the newly
|
||||||
// returned state to the roomserver to update our local view.
|
// returned state to the roomserver to update our local view.
|
||||||
if err = roomserverAPI.SendEventWithState(
|
if err = roomserverAPI.SendEventWithState(
|
||||||
ctx, r.rsAPI,
|
context.Background(),
|
||||||
|
r.rsAPI,
|
||||||
roomserverAPI.KindNew,
|
roomserverAPI.KindNew,
|
||||||
respState,
|
respState,
|
||||||
event.Headered(respMakeJoin.RoomVersion),
|
event.Headered(respMakeJoin.RoomVersion),
|
||||||
|
@ -253,15 +246,9 @@ func (r *FederationInternalAPI) performJoinUsingServer(
|
||||||
nil,
|
nil,
|
||||||
false,
|
false,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
logrus.WithFields(logrus.Fields{
|
return fmt.Errorf("roomserverAPI.SendEventWithState: %w", err)
|
||||||
"room_id": roomID,
|
|
||||||
"user_id": userID,
|
|
||||||
}).WithError(err).Error("Failed to send room join response to roomserver")
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}()
|
|
||||||
|
|
||||||
<-ctx.Done()
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue