Return sooner when joining room over federation

This commit is contained in:
Neil Alexander 2020-04-30 11:14:04 +01:00
parent 77fe509031
commit 14398e0020
2 changed files with 37 additions and 17 deletions

View file

@ -332,6 +332,7 @@ func (r joinRoomReq) joinRoomUsingServer(roomID string, server gomatrixserverlib
RoomID: roomID, RoomID: roomID,
UserID: r.userID, UserID: r.userID,
ServerName: server, ServerName: server,
Content: r.content,
} }
fedJoinRes := federationSenderAPI.PerformJoinResponse{} fedJoinRes := federationSenderAPI.PerformJoinResponse{}
if err := r.fsAPI.PerformJoin(r.req.Context(), &fedJoinReq, &fedJoinRes); err != nil { if err := r.fsAPI.PerformJoin(r.req.Context(), &fedJoinReq, &fedJoinRes); err != nil {

View file

@ -9,6 +9,7 @@ import (
"github.com/matrix-org/dendrite/federationsender/query/perform" "github.com/matrix-org/dendrite/federationsender/query/perform"
"github.com/matrix-org/dendrite/roomserver/version" "github.com/matrix-org/dendrite/roomserver/version"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
"github.com/sirupsen/logrus"
) )
// PerformJoinRequest implements api.FederationSenderInternalAPI // PerformJoinRequest implements api.FederationSenderInternalAPI
@ -87,12 +88,28 @@ func (r *FederationSenderInternalAPI) PerformJoin(
return fmt.Errorf("r.federation.SendJoin: %w", err) return fmt.Errorf("r.federation.SendJoin: %w", err)
} }
// At this point, if the above /send_join didn't return an error,
// then the resident servers think we're in the room. We need
// to verify the state and auth chain and notify the roomserver
// but this can take an awful long time in big rooms and there's
// every possibility that client may give up waiting on this CS
// API request long before that. Therefore for now, until we
// have a /confirm_join step, just let the client think that the
// request succeeded and work it out in our own time. There's
// every possibility this might fail, and if so, the room will
// just never appear in the sync stream. That's about the best
// we can do for now.
go func() {
// Don't expire with the original request context.
ctx := context.Background()
// Check that the send_join response was valid. // Check that the send_join response was valid.
joinCtx := perform.JoinContext(r.federation, r.keyRing) joinCtx := perform.JoinContext(r.federation, r.keyRing)
if err = joinCtx.CheckSendJoinResponse( if err = joinCtx.CheckSendJoinResponse(
ctx, event, request.ServerName, respMakeJoin, respSendJoin, ctx, event, request.ServerName, respMakeJoin, respSendJoin,
); err != nil { ); err != nil {
return fmt.Errorf("perform.JoinRequest.CheckSendJoinResponse: %w", err) logrus.WithError(err).Errorf("perform.JoinRequest.CheckSendJoinResponse failed")
return
} }
// If we successfully performed a send_join above then the other // If we successfully performed a send_join above then the other
@ -103,8 +120,10 @@ func (r *FederationSenderInternalAPI) PerformJoin(
respSendJoin.ToRespState(), respSendJoin.ToRespState(),
event.Headered(respMakeJoin.RoomVersion), event.Headered(respMakeJoin.RoomVersion),
); err != nil { ); err != nil {
return fmt.Errorf("r.producer.SendEventWithState: %w", err) logrus.WithError(err).Errorf("r.producer.SendEventWithState failed")
return
} }
}()
// Everything went to plan. // Everything went to plan.
return nil return nil