From ce6bb51049776ae4ae2ce99a2482579dfb7f3d83 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Mon, 30 Sep 2024 13:43:21 -0700 Subject: [PATCH] Make PUT /instance/state 503 when waiting to init Also, I noticed that the `PUT /instance/state` API route would return a `NoInstance` error when trying to change the state returned a `VmError::WaitingToInitialize`, which seemed potentially bad: this would result in a sled-agent that tries to send a state change request to a still-initializing VM to believe it's Permanently Gone, and mark it as `Failed`, tear down the zone, and so on. Which seems rude of it! I don't think this is likely to be a problem in practice since IIRC both sled-agent and Nexus will not try to send state change requests to instances that they understand to be still initializing, but it seemed good to not return the INSTANCE IS PERMANENTLY GONE error code here. Now, we return a 503, so the sled-agent will just know it needs to wait for a bit. --- bin/propolis-server/src/lib/server.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/propolis-server/src/lib/server.rs b/bin/propolis-server/src/lib/server.rs index 48b889f44..711648d6f 100644 --- a/bin/propolis-server/src/lib/server.rs +++ b/bin/propolis-server/src/lib/server.rs @@ -426,7 +426,10 @@ async fn instance_state_put( .put_state(requested_state) .map(|_| HttpResponseUpdatedNoContent {}) .map_err(|e| match e { - VmError::WaitingToInitialize => not_created_error(), + VmError::WaitingToInitialize => HttpError::for_unavail( + None, + "instance is still initializing".to_string(), + ), VmError::ForbiddenStateChange(reason) => HttpError::for_status( Some(format!("instance state change not allowed: {}", reason)), hyper::StatusCode::FORBIDDEN,