Skip to content
This repository has been archived by the owner on Dec 15, 2021. It is now read-only.

functions should have a timeout #365

Closed
alban opened this issue Oct 12, 2017 · 8 comments
Closed

functions should have a timeout #365

alban opened this issue Oct 12, 2017 · 8 comments
Assignees

Comments

@alban
Copy link
Contributor

alban commented Oct 12, 2017

To protect against infinite loops taking the cpu, functions should have a timeout.

Example of function in Python to test this:

def foobar(context):
  while 1:
    pass
  return ""

Once the function is triggered, the user cannot cancel the execution of the function without killing the process or the pod.

AWS Lambda have the following timeout:

Q: How long can an AWS Lambda function execute?

All calls made to AWS Lambda must complete execution within 300 seconds. The default timeout is 3 seconds, but you can set the timeout to any value between 1 and 300 seconds.

@kishoreacesurf
Copy link

Is there any alternative for this?

@andresmgot
Copy link
Contributor

@kishoreacesurf what do you mean with alternative?

@andresmgot
Copy link
Contributor

@alban @kishoreacesurf the feature is available since with Kubeless v0.3.0. The default timeout is set to 180s but you can modify this value using the flag --timeout. Please give it a try and reopen this issue if you find any trouble.

@johanatan
Copy link

@andresmgot what is the maximum value that can be specified for --timeout ?

@andresmgot
Copy link
Contributor

that may depend on the runtime, note that we are just setting the value of the timeout reading it from an env var that we set depending on the value set with --timeout. See NodeJS for example: https://github.com/kubeless/kubeless/blob/master/docker/runtime/nodejs/kubeless.js#L28

@JoHuang
Copy link

JoHuang commented Jul 27, 2019

AWS lambda has a hard timeout like 30s. I would like to have this behavior before using in production.

for Node.js:
Current implementation which using vm.runInNewContext can only timeout sync part of a script.
nodejs/node#3020

Here is my thought:
Can we use worker thread to run scripts in some thread pool?
Then at least we may simply timeout scripts by setTimeout + worker.terminate in main thread.
Does it make sense?

@addaleax
Copy link

Can we use worker thread to run scripts in some thread pool?
Then at least we may simply timeout scripts by setTimeout + worker.terminate in main thread.
Does it make sense?

As far as Node.js is concerned, I think that’s the best in-process solution for working around nodejs/node#3020.

@andresmgot
Copy link
Contributor

andresmgot commented Jul 29, 2019

That may be interesting to investigate. Could someone work in a POC of how that might work? The code of the NodeJS runtime is here: https://github.com/kubeless/runtimes/blob/master/stable/nodejs/kubeless.js

I am not sure if we can maintain the current function isolation if we change the approach.

Also note that the use case between lambda and kubeless changes. With lambda you are being charged for execution time (which is not the case in Kubeless). That's why timeouts here are bigger. In any case, it's true that timeouts should work as expected.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants