question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

What is duktape's policy when receiving signals?

See original GitHub issue

I’m curious about correctly writing an FFI to duktape from GHC Haskell. There are other Haskell bindings, but I’m not sure whether they’re correct or just coincidentally working OK. I don’t have much experience with signal handling in C, so I’m going off what I’ve read.

The RTS uses signals to trigger context switches and other threading features. In particular, using the system timers API, SIGVTALRM will be triggered on a regular basis. The C code being called apparently needs to be aware of this.

I believe it’s possible for me to write some small wrapper C code to register a signal mask to prevent these signals from bothering the duktape functions.


Secondly, when declaring a foreign function, I can choose whether it is interruptible or not. If I mark it interruptible, that means that if I terminate the Haskell (green) thread using regular Haskell code, SIGPIPE will be signalled to the OS thread (see also). What does duktape do when it receives SIGPIPE, and SIGINT for that matter? Is it manifested as a JS exception? What’s the relationship between “protected” functions and non-protected ones in this setting? I’ve read through the user guide a few times, but wasn’t able to find clarity on this.


Use-case: I’d like to be able to execute PureScript from my Haskell code to have server-side rendering and validation as well as front-end. I want to do one-shot runs of code. Ideally I could execute the JS via duktape, which has fine-grained control over what functionality is available (e.g. I need timers API (setTimeout, used for asynchronous runs by a library I’m using, but not actual waiting), but not I/O).

However, due to the messiness in dealing with GHC’s RTS, I’m wondering whether correctness-wise it may be easier to launch a nodejs program as a pipe and parse JSON output? 🤔 But then you have a much heavier dependency that needs to be kept around somewhere to be launched, etc. Trade-offs.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
svaaralacommented, Feb 8, 2021

The interrupt check is really quite simple at present and there has been no thought about executing Duktape calls within the interrupt check.

But, I think calling a function from the interrupt check should work fine because a function may be get called for various other reasons within the bytecode executor - e.g. a property read may invoke a Proxy trap, and the bytecode executor is generally unaware of the situation.

If this doesn’t work, it should be relatively easy to fix because the executor must tolerate recursive calls elsewhere.

0reactions
aksyomcommented, Feb 8, 2021

When the DUK_USE_EXEC_TIMEOUT_CHECK -macro is executed by the bytecode executor, is it safe to call a global function object within the duk_context being interrupted?

If it is not safe to call a function, would it be safe to modify a global value within the duk_context?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Duktape Programmer's Guide
Duktape is an embeddable ECMAScript® engine with a focus on portability and ... Getting started guides you through downloading, compiling, ...
Read more >
Protected version duk_json_decode() · Issue #386 - GitHub
I'm just trying to figure out what a consistent policy would be so that I won't end up adding hundreds of protected calls...
Read more >
duktape-wasm - npm Package Health Analysis - Snyk
An important project maintenance signal to consider for duktape-wasm is that it hasn't seen any new versions released to npm in the past...
Read more >
Signals (Debugging with GDB) - sourceware.org
5.4 Signals. A signal is an asynchronous event that can happen in a program. The operating system defines the possible kinds of signals,...
Read more >
CSS Alignment Made Simple - Morioh
CSS is seen as an impediment in web development for many of us. Most of the time it looks like even when you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found