Skip to content

Commit

Permalink
Skip an async callback function when the UpdateBootFlagsAction object…
Browse files Browse the repository at this point in the history
… is destroyed

As the callback to MarkBootSuccessfulAsync, UpdateBootFlagsAction's
member function CompleteUpdateBootFlags() can still be called even after
the current UpdateBootFlagsAction object get destroyed by the action
processor. We want to set a static flag in TerminateProcessing() and check
its value before executing the callback function.

An alternative way is to save and propagate the TaskId when scheduling the
task in MarkBootSuccessfulAsync, and cancel the task in UpdateBootFlagsAction's
TerminateProcessing().

Bug: 123720545
Test: No longer hit the CHECK after injecting StopProcessing.
Change-Id: I98d2cc7b94d4059fb897b89932969b61936e8c2e
  • Loading branch information
Tianjie Xu committed May 22, 2019
1 parent ffb7595 commit e1f55b0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 16 additions & 1 deletion update_boot_flags_action.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@ void UpdateBootFlagsAction::PerformAction() {
}
}

void UpdateBootFlagsAction::CompleteUpdateBootFlags(bool successful) {
void UpdateBootFlagsAction::TerminateProcessing() {
is_running_ = false;
}

void UpdateBootFlagsAction::CompleteUpdateBootFlags(bool successful) {
if (!successful) {
// We ignore the failure for now because if the updating boot flags is flaky
// or has a bug in a specific release, then blocking the update can cause
Expand All @@ -61,6 +64,18 @@ void UpdateBootFlagsAction::CompleteUpdateBootFlags(bool successful) {
// TODO(ahassani): Add new error code metric for kUpdateBootFlagsFailed.
LOG(ERROR) << "Updating boot flags failed, but ignoring its failure.";
}

// As the callback to MarkBootSuccessfulAsync, this function can still be
// called even after the current UpdateBootFlagsAction object get destroyed by
// the action processor. In this case, check the value of the static variable
// |is_running_| and skip executing the callback function.
if (!is_running_) {
LOG(INFO) << "UpdateBootFlagsAction is no longer running.";
return;
}

is_running_ = false;

updated_boot_flags_ = true;
processor_->ActionComplete(this, ErrorCode::kSuccess);
}
Expand Down
2 changes: 2 additions & 0 deletions update_boot_flags_action.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class UpdateBootFlagsAction : public AbstractAction {

void PerformAction() override;

void TerminateProcessing() override;

static std::string StaticType() { return "UpdateBootFlagsAction"; }
std::string Type() const override { return StaticType(); }

Expand Down

0 comments on commit e1f55b0

Please sign in to comment.