Fail teardown when control withdrawal fails
This commit is contained in:
parent
da7557b850
commit
a9c9cf7ab3
2 changed files with 51 additions and 11 deletions
|
|
@ -449,9 +449,10 @@ impl LifecycleAdapter for ProductionLifecycleAdapter<'_> {
|
|||
LifecycleAction::ReleasePreparedLowerLease => self.release_prepared_lower(),
|
||||
LifecycleAction::GracefulSupervisorExit => self.graceful_exit(),
|
||||
LifecycleAction::BeginTeardown => {
|
||||
if let Some(control) = self.published_control.take() {
|
||||
control.withdraw();
|
||||
if let Some(control) = self.published_control.as_ref() {
|
||||
control.withdraw().map_err(failure)?;
|
||||
}
|
||||
self.published_control.take();
|
||||
Ok(())
|
||||
}
|
||||
LifecycleAction::FinishTeardown => {
|
||||
|
|
|
|||
|
|
@ -1010,9 +1010,12 @@ impl PublishedControlFace {
|
|||
}
|
||||
|
||||
/// Withdraws exact discovery and connection paths while retaining live accepted streams.
|
||||
pub fn withdraw(&self) {
|
||||
remove_if_identity_matches(&self.paths.socket, self.socket_identity);
|
||||
remove_if_identity_matches(&self.paths.identity, self.identity_file_identity);
|
||||
///
|
||||
/// # Errors
|
||||
/// Refuses changed artifacts, removal failures, or artifacts that remain after removal.
|
||||
pub fn withdraw(&self) -> Result<(), ControlError> {
|
||||
remove_exact_if_identity_matches(&self.paths.socket, self.socket_identity)?;
|
||||
remove_exact_if_identity_matches(&self.paths.identity, self.identity_file_identity)
|
||||
}
|
||||
|
||||
/// Accepts and serves one TLS connection. Registered connections remain live until EOF.
|
||||
|
|
@ -1260,7 +1263,32 @@ impl PublishedControlFace {
|
|||
|
||||
impl Drop for PublishedControlFace {
|
||||
fn drop(&mut self) {
|
||||
self.withdraw();
|
||||
remove_if_identity_matches(&self.paths.socket, self.socket_identity);
|
||||
remove_if_identity_matches(&self.paths.identity, self.identity_file_identity);
|
||||
}
|
||||
}
|
||||
|
||||
fn remove_exact_if_identity_matches(
|
||||
path: &Path,
|
||||
expected: FileIdentity,
|
||||
) -> Result<(), ControlError> {
|
||||
let metadata = match std::fs::symlink_metadata(path) {
|
||||
Ok(metadata) => metadata,
|
||||
Err(error) if error.kind() == io::ErrorKind::NotFound => return Ok(()),
|
||||
Err(error) => return Err(error.into()),
|
||||
};
|
||||
if FileIdentity::from_metadata(&metadata) != expected {
|
||||
return Err(ControlError::InvalidPublication(
|
||||
"publication artifact identity changed before withdrawal",
|
||||
));
|
||||
}
|
||||
std::fs::remove_file(path)?;
|
||||
match std::fs::symlink_metadata(path) {
|
||||
Err(error) if error.kind() == io::ErrorKind::NotFound => Ok(()),
|
||||
Err(error) => Err(error.into()),
|
||||
Ok(_) => Err(ControlError::InvalidPublication(
|
||||
"publication artifact remained after withdrawal",
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue