Skip to content

Commit

Permalink
fix(wasi): WsaiThreadRunGuard: Don't overwrite finished state
Browse files Browse the repository at this point in the history
Do not overwrite the finished state if the task already has a result.

Prevents mistakenly propagating errors from the WasiThreadRunGuard drop
implementation.
  • Loading branch information
theduke committed Mar 2, 2023
1 parent 43fb0cc commit c7c9c8c
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/wasi/src/os/task/task_join_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ impl TaskStatus {
_ => None,
}
}

/// Returns `true` if the task status is [`Finished`].
///
/// [`Finished`]: TaskStatus::Finished
#[must_use]
pub fn is_finished(&self) -> bool {
matches!(self, Self::Finished(..))
}
}

#[derive(thiserror::Error, Debug)]
Expand Down Expand Up @@ -88,6 +96,11 @@ impl OwnedTaskStatus {

/// Marks the task as finished.
pub(super) fn set_finished(&self, res: Result<ExitCode, Arc<WasiRuntimeError>>) {
// Don't overwrite a previous finished state.
if self.status().is_finished() {
return;
}

let inner = match res {
Ok(code) => Ok(code),
Err(err) => {
Expand All @@ -98,7 +111,6 @@ impl OwnedTaskStatus {
}
}
};

self.watch.send(TaskStatus::Finished(inner)).ok();
}

Expand Down

0 comments on commit c7c9c8c

Please sign in to comment.