Skip to content
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

cloud.Function timeout not working in simulator - vm.runInContext doesn't seem to kill the function #1980

Closed
tsuf239 opened this issue Apr 4, 2023 · 4 comments · Fixed by #5554
Assignees
Labels
🐛 bug Something isn't working 🎨 sdk SDK 🕹️ simulator Related to the `sim` compilation target

Comments

@tsuf239
Copy link
Contributor

tsuf239 commented Apr 4, 2023

Community Note

Please vote by adding a 👍 reaction to the issue to help us prioritize.
If you are interested to work on this issue, please leave a comment.

I tried this:

run a cloud function with a timeout set to 1s, that is calling a timeout of 1.5s.

bring cloud;

let c = new cloud.Counter();

resource Helper {
  init () {}
  extern "./sleep.js" inflight sleep(time_ms: num);
}

let helper = new Helper();

let f = new cloud.Function(inflight () => {
  // call sleep
  helper.sleep(1500);
  c.inc();
}, cloud.FunctionProps {timeout: 1s});

// doesn't work yet- see issue: 
new cloud.Function(inflight () => {
try{
  f.invoke("");
} catch (err) {}
  assert(c.peek() == 0);
}) as "test:function timeout";

I expected this:

The process that the function is running on stops, and an error is thrown.

Instead, this happened:

The function exceeded the timeout. No error was thrown.
it happened because of vm.runInContext doesn't "wait" for the inflight code to run, but executes it synchronically (without "await"). We suspect it runs on a different process and is not interrupted by the timeout completion.

Is there a workaround?

No response

Component:

SDK

Wing Version:

No response

Node.js Version:

No response

Platform(s):

No response

Anything else?

No response

@tsuf239 tsuf239 added the 🐛 bug Something isn't working label Apr 4, 2023
@monadabot monadabot added this to Wing Apr 4, 2023
@github-project-automation github-project-automation bot moved this to 🆕 New - not properly defined in Wing Apr 4, 2023
@staycoolcall911 staycoolcall911 moved this from 🆕 New - not properly defined to 🤝 Backlog - handoff to owners in Wing Apr 14, 2023
@github-actions
Copy link

Hi,

This issue hasn't seen activity in 60 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days.
Feel free to re-open this issue when there's an update or relevant information to be added.
Thanks!

@github-actions
Copy link

Hi,

This issue hasn't seen activity in 60 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days.
Feel free to re-open this issue when there's an update or relevant information to be added.
Thanks!

@github-actions github-actions bot added the Stale label Aug 14, 2023
@Chriscbr Chriscbr changed the title vm.runInContext doesn't seem to kill the function after timeout cloud.Function timeout not working in simulator - vm.runInContext doesn't seem to kill the function Dec 20, 2023
@Chriscbr Chriscbr added the 🕹️ simulator Related to the `sim` compilation target label Dec 20, 2023
@Chriscbr
Copy link
Contributor

Chriscbr commented Dec 20, 2023

Based on this issue nodejs/node#3020 it seems like the behavior we're seeing is unavoidable as long as we're using Node's vm capabilities.

Possible solution: #4725

@Chriscbr Chriscbr added this to the Winglang Stable Release milestone Mar 4, 2024
@mergify mergify bot closed this as completed in #5554 Mar 6, 2024
mergify bot pushed a commit that referenced this issue Mar 6, 2024
This pull request fixes a range of funky JavaScript issues we've had running inflight code in the Wing simulator by switching internally from running JS code in a `vm` to running JS code using Node.js child processes.

The main issues with `vm` are:
- several third-party JavaScript dependencies behave differently when executed inside a `vm` and outside. This may be related to differences in vm behavior as described in nodejs/node#28823
- we cannot easily stop/kill code executing in a `vm` process, making it impossible to simulate cloud.Function timeouts

Fixes #1980
Fixes #4131
Fixes #4118
Fixes #4792

Closes #4725

## Checklist

- [x] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted)
- [x] Description explains motivation and solution
- [x] Tests added (always)
- [ ] Docs updated (only required for features)
- [ ] Added `pr/e2e-full` label if this feature requires end-to-end testing

*By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
@github-project-automation github-project-automation bot moved this from 🤝 Backlog - handoff to owners to ✅ Done in Wing Mar 6, 2024
@monadabot
Copy link
Contributor

Congrats! 🚀 This was released in Wing 0.59.43.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working 🎨 sdk SDK 🕹️ simulator Related to the `sim` compilation target
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants