Skip to content

Add terminate execution API. #268

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Mar 1, 2022

Conversation

chaoqin-li1123
Copy link
Contributor

Enable v8 wasm vm to terminate execution.
Signed-off-by: chaoqin-li1123 [email protected]

Signed-off-by: chaoqin-li1123 <[email protected]>
chaoqin-li1123 added 3 commits February 24, 2022 21:59
Signed-off-by: chaoqin-li1123 <[email protected]>
Signed-off-by: chaoqin-li1123 <[email protected]>
Signed-off-by: chaoqin-li1123 <[email protected]>
@@ -311,6 +311,7 @@ class WasmVm {

// Integrator operations.
std::unique_ptr<WasmVmIntegration> &integration() { return integration_; }
virtual void terminateExecution() {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Could you move it higher? Right now, it's between 2 "integration" functions. Perhaps before isFailed()?
  2. I think using terminate as a name should be enough.
  3. Please mark it as a pure virtual function.
  4. Some documentation would be useful.

src/v8/v8.cc Outdated
@@ -66,6 +68,14 @@ class V8 : public WasmVm {
const std::unordered_map<uint32_t, std::string> &function_names) override;
std::string_view getPrecompiledSectionName() override;
bool link(std::string_view debug_name) override;
void terminateExecution() override {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you split declaration and implementation, like other functions in the code?

Also, the placement should match that in the wasm_vm.h.

src/v8/v8.cc Outdated
while (isolate->IsExecutionTerminating()) {
std::this_thread::yield();
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we log this event? e.g.

Suggested change
}
integration()->trace("[host->vm] Terminated");
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, we should probably mark the VM as failed, so that other code paths won't try to continue execution.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't mark it as failed, the user can may reuse it. If we mark it as fail explicitly, we don't need to wait for the termination to finish.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think WasmVM is going to be reusable after we terminate it in the middle of the call. Risking resuming it in a weird state doesn't seem to be worth the trouble.

Also, I think we might be already marking it as failed, since the terminate call is going to happen during a callback, so it's going to results in a trap, which marks WasmVM as failed... but perhaps it makes sense to mark it explicitly to cover any future non-callback cases?

As for waiting for the termination to finish, I'd prefer to leave it in. It seems to be always instant in my tests (i.e. IsExecutionTerminating() is never true), and this way we can be sure that the WasmVM not busy anymore, so that vm->terminate(); delete vm; won't result in a crash.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that fail() is not thread safe, but terminate() should be, so I get a tsan error. Do you have any suggestion?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's drop explicit fail() call for now, since it's going to turn into a trap and failed WasmVM anyway when unrolling.

chaoqin-li1123 added 6 commits February 27, 2022 02:23
Signed-off-by: chaoqin-li1123 <[email protected]>
Signed-off-by: chaoqin-li1123 <[email protected]>
Signed-off-by: chaoqin-li1123 <[email protected]>
Signed-off-by: chaoqin-li1123 <[email protected]>
Signed-off-by: chaoqin-li1123 <[email protected]>
Signed-off-by: chaoqin-li1123 <[email protected]>
@chaoqin-li1123
Copy link
Contributor Author

./retest

@chaoqin-li1123
Copy link
Contributor Author

/retest

@PiotrSikora
Copy link
Member

There is no /retest here. I re-kicked the CI, but in the future you can simply push an empty commit to do that yourself.

Copy link
Member

@PiotrSikora PiotrSikora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, with a few style nits.

Signed-off-by: chaoqin-li1123 <[email protected]>
Copy link
Member

@PiotrSikora PiotrSikora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@PiotrSikora PiotrSikora changed the title add terminate execution api Add terminate execution API. Mar 1, 2022
@PiotrSikora PiotrSikora merged commit 579de9b into proxy-wasm:master Mar 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants