aboutsummaryrefslogtreecommitdiff
path: root/clientapi
diff options
context:
space:
mode:
authorNeil Alexander <neilalexander@users.noreply.github.com>2020-10-07 15:29:14 +0100
committerGitHub <noreply@github.com>2020-10-07 15:29:14 +0100
commit533006141ecbe18fc82d63a400cea57def8791d8 (patch)
tree5eaef5d130a3b582ab3ecd0cc16fe3ddc1304f9e /clientapi
parentd821f9d3c92adde5b0576de03d0d44ffce5f0182 (diff)
Return 200 on join before time out (#1493)
* Return 200 on join afer 15 seconds if nothing better has happened by that point * Return 202 instead, 20 second timeout
Diffstat (limited to 'clientapi')
-rw-r--r--clientapi/routing/joinroom.go38
1 files changed, 28 insertions, 10 deletions
diff --git a/clientapi/routing/joinroom.go b/clientapi/routing/joinroom.go
index c1011357..578aaec5 100644
--- a/clientapi/routing/joinroom.go
+++ b/clientapi/routing/joinroom.go
@@ -16,9 +16,11 @@ package routing
import (
"net/http"
+ "time"
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
"github.com/matrix-org/dendrite/clientapi/httputil"
+ "github.com/matrix-org/dendrite/clientapi/jsonerror"
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
"github.com/matrix-org/dendrite/userapi/api"
"github.com/matrix-org/dendrite/userapi/storage/accounts"
@@ -74,16 +76,32 @@ func JoinRoomByIDOrAlias(
}
// Ask the roomserver to perform the join.
- rsAPI.PerformJoin(req.Context(), &joinReq, &joinRes)
- if joinRes.Error != nil {
- return joinRes.Error.JSONResponse()
- }
+ done := make(chan util.JSONResponse, 1)
+ go func() {
+ defer close(done)
+ rsAPI.PerformJoin(req.Context(), &joinReq, &joinRes)
+ if joinRes.Error != nil {
+ done <- joinRes.Error.JSONResponse()
+ } else {
+ done <- util.JSONResponse{
+ Code: http.StatusOK,
+ // TODO: Put the response struct somewhere internal.
+ JSON: struct {
+ RoomID string `json:"room_id"`
+ }{joinRes.RoomID},
+ }
+ }
+ }()
- return util.JSONResponse{
- Code: http.StatusOK,
- // TODO: Put the response struct somewhere internal.
- JSON: struct {
- RoomID string `json:"room_id"`
- }{joinRes.RoomID},
+ // Wait either for the join to finish, or for us to hit a reasonable
+ // timeout, at which point we'll just return a 200 to placate clients.
+ select {
+ case <-time.After(time.Second * 20):
+ return util.JSONResponse{
+ Code: http.StatusAccepted,
+ JSON: jsonerror.Unknown("The room join will continue in the background."),
+ }
+ case result := <-done:
+ return result
}
}