@@ -120,6 +120,23 @@ impl Service<Request<IncomingBody>> for BalancerService {
120
120
} ;
121
121
122
122
let room_name: RoomName = room_name. to_owned ( ) . into ( ) ;
123
+ if room_name. to_string ( ) == "list" {
124
+ // special case for listing rooms -- "list" is never a valid room name
125
+ return match list_rooms ( ctx. clone ( ) ) . await {
126
+ Ok ( res) => Ok ( res) ,
127
+ Err ( e) => {
128
+ error ! ( "error listing rooms: {}" , e) ;
129
+ mk_response ( "error listing rooms" . to_owned ( ) )
130
+ }
131
+ } ;
132
+ }
133
+
134
+ let ctx_read = ctx. read ( ) . await ;
135
+ if ctx_read. monoliths . len ( ) == 0 {
136
+ debug ! ( message = "no monoliths" , request_id, room = %room_name) ;
137
+ return Ok ( no_monoliths ( ) ) ;
138
+ }
139
+
123
140
if is_websocket_upgrade ( & req) {
124
141
debug ! ( message = "upgrading to websocket" , request_id, room = %room_name) ;
125
142
let ( response, websocket) = match upgrade ( req, None ) {
@@ -143,17 +160,7 @@ impl Service<Request<IncomingBody>> for BalancerService {
143
160
144
161
// Return the response so the spawned future can continue.
145
162
Ok ( response)
146
- } else if room_name. to_string ( ) == "list" {
147
- // special case for listing rooms
148
- match list_rooms ( ctx. clone ( ) ) . await {
149
- Ok ( res) => Ok ( res) ,
150
- Err ( e) => {
151
- error ! ( "error listing rooms: {}" , e) ;
152
- mk_response ( "error listing rooms" . to_owned ( ) )
153
- }
154
- }
155
163
} else {
156
- let ctx_read = ctx. read ( ) . await ;
157
164
let monolith =
158
165
if let Some ( locator) = ctx_read. rooms_to_monoliths . get ( & room_name) {
159
166
info ! (
@@ -175,7 +182,7 @@ impl Service<Request<IncomingBody>> for BalancerService {
175
182
}
176
183
}
177
184
} else {
178
- mk_response ( "no monoliths available" . to_owned ( ) )
185
+ Ok ( no_monoliths ( ) )
179
186
}
180
187
}
181
188
}
@@ -195,7 +202,7 @@ impl Service<Request<IncomingBody>> for BalancerService {
195
202
}
196
203
}
197
204
} else {
198
- mk_response ( "no monoliths available" . to_owned ( ) )
205
+ Ok ( no_monoliths ( ) )
199
206
}
200
207
}
201
208
_ => Ok ( not_found ( ) ) ,
@@ -220,6 +227,15 @@ fn interval_server_error() -> Response<Full<Bytes>> {
220
227
. unwrap ( )
221
228
}
222
229
230
+ fn no_monoliths ( ) -> Response < Full < Bytes > > {
231
+ Response :: builder ( )
232
+ . status ( StatusCode :: SERVICE_UNAVAILABLE )
233
+ . body ( Full :: new (
234
+ "No monoliths available to handle request." . into ( ) ,
235
+ ) )
236
+ . expect ( "failed to build NO_MONOLITHS" )
237
+ }
238
+
223
239
async fn proxy_request (
224
240
in_req : Request < IncomingBody > ,
225
241
target : & BalancerMonolith ,
0 commit comments