I'm looking at adding a timeout option to my GoAWK script interpreter using either a timeout or a context value. This is mainly for safety when using it in an embedded context, for example to avoid someone doing a denial-of-service attack by submitting a `BEGIN { while (1); }` script.
This seems simple to do using a timer or context.WithTimeout, and it will time out and return to the caller ... but will continue to run the while loop in the background, eating CPU cycles and leaking a goroutine. So I'm trying to figure out the best way for the interpreter to check for the timeout at various points and terminate if the timeout has been reached. github.com/yuin/gopher-lua does this by checking ctx.Done() every time around its bytecode loop, but it adds a lot of overhead. I think in GoAWK I'd at least need to check the timeout when handling the "for", "while", and "do-while" statements, as well as the constructs that call os/exec (presumably by passing the ctx down). And I think it'd have to check every statement execution as well. And I'm sure it'll cause a fair bit of performance degradation. Are there better / more performant ways to handle this? GitHub issue reference: https://github.com/benhoyt/goawk/pull/26 Thanks, Ben -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAL9jXCFKxghRjCaLhjB63HarybvBOFubjxMEXZ6SF1bD-_W8sw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.