mirror of
https://github.com/matrix-org/dendrite
synced 2024-12-14 15:22:50 +00:00
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
This commit is contained in:
parent
d821f9d3c9
commit
533006141e
1 changed files with 28 additions and 10 deletions
|
@ -16,9 +16,11 @@ package routing
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
|
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
|
||||||
"github.com/matrix-org/dendrite/clientapi/httputil"
|
"github.com/matrix-org/dendrite/clientapi/httputil"
|
||||||
|
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||||
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
|
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
|
||||||
"github.com/matrix-org/dendrite/userapi/api"
|
"github.com/matrix-org/dendrite/userapi/api"
|
||||||
"github.com/matrix-org/dendrite/userapi/storage/accounts"
|
"github.com/matrix-org/dendrite/userapi/storage/accounts"
|
||||||
|
@ -74,16 +76,32 @@ func JoinRoomByIDOrAlias(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ask the roomserver to perform the join.
|
// Ask the roomserver to perform the join.
|
||||||
|
done := make(chan util.JSONResponse, 1)
|
||||||
|
go func() {
|
||||||
|
defer close(done)
|
||||||
rsAPI.PerformJoin(req.Context(), &joinReq, &joinRes)
|
rsAPI.PerformJoin(req.Context(), &joinReq, &joinRes)
|
||||||
if joinRes.Error != nil {
|
if joinRes.Error != nil {
|
||||||
return joinRes.Error.JSONResponse()
|
done <- joinRes.Error.JSONResponse()
|
||||||
}
|
} else {
|
||||||
|
done <- util.JSONResponse{
|
||||||
return util.JSONResponse{
|
|
||||||
Code: http.StatusOK,
|
Code: http.StatusOK,
|
||||||
// TODO: Put the response struct somewhere internal.
|
// TODO: Put the response struct somewhere internal.
|
||||||
JSON: struct {
|
JSON: struct {
|
||||||
RoomID string `json:"room_id"`
|
RoomID string `json:"room_id"`
|
||||||
}{joinRes.RoomID},
|
}{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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue