mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-23 14:53:10 -06:00
Return 200 on join afer 15 seconds if nothing better has happened by that point
This commit is contained in:
parent
d821f9d3c9
commit
fa41fb0eeb
|
|
@ -16,6 +16,7 @@ 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"
|
||||||
|
|
@ -73,17 +74,34 @@ func JoinRoomByIDOrAlias(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ask the roomserver to perform the join.
|
// This is the default response that we'll return, assuming nothing
|
||||||
rsAPI.PerformJoin(req.Context(), &joinReq, &joinRes)
|
// goes wrong within the timeframe.
|
||||||
if joinRes.Error != nil {
|
ok := util.JSONResponse{
|
||||||
return joinRes.Error.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},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ask the roomserver to perform the join.
|
||||||
|
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 <- ok
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
// 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 * 15):
|
||||||
|
return ok
|
||||||
|
case result := <-done:
|
||||||
|
return result
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue