From 6386c1a7afbf49f035b6c87abb602fef659c4038 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 6 Dec 2019 00:39:16 +0100 Subject: [PATCH 1/6] cli: add `--trace-atomics-wait` flag Adds a flag that helps with debugging deadlocks due to incorrectly implemented `Atomics.wait()` calls. --- benchmark/worker/atomics-wait.js | 14 +++++ doc/api/cli.md | 20 +++++++ doc/node.1 | 4 ++ src/node.cc | 43 ++++++++++++++ src/node_options.cc | 4 ++ src/node_options.h | 1 + test/parallel/test-trace-atomics-wait.js | 74 ++++++++++++++++++++++++ 7 files changed, 160 insertions(+) create mode 100644 benchmark/worker/atomics-wait.js create mode 100644 test/parallel/test-trace-atomics-wait.js diff --git a/benchmark/worker/atomics-wait.js b/benchmark/worker/atomics-wait.js new file mode 100644 index 00000000000000..d78e31c26368c8 --- /dev/null +++ b/benchmark/worker/atomics-wait.js @@ -0,0 +1,14 @@ +'use strict'; + +const common = require('../common.js'); +const bench = common.createBenchmark(main, { + n: [1e7] +}); + +function main({ n }) { + const i32arr = new Int32Array(new SharedArrayBuffer(4)); + bench.start(); + for (let i = 0; i < n; i++) + Atomics.wait(i32arr, 0, 1); // Will return immediately. + bench.end(n); +} diff --git a/doc/api/cli.md b/doc/api/cli.md index e6310b279f424c..25796d707b0319 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -816,6 +816,25 @@ added: v12.0.0 Set default [`tls.DEFAULT_MIN_VERSION`][] to 'TLSv1.3'. Use to disable support for TLSv1.2, which is not as secure as TLSv1.3. +### `--trace-atomics-wait` + + +Print short summaries of calls to `Atomics.wait()` to stderr. +The output could look like this: + +```text +[Thread 0] Atomics.wait(0x55d134fe4290 + 0, 1, inf) started +[Thread 0] Atomics.wait(0x55d134fe4290 + 0, 1, inf) did not wait because the values mismatched +[Thread 0] Atomics.wait(0x55d134fe4290 + 0, 0, 10) started +[Thread 0] Atomics.wait(0x55d134fe4290 + 0, 0, 10) timed out +[Thread 0] Atomics.wait(0x55d134fe4290 + 4, 0, inf) started +[Thread 1] Atomics.wait(0x55d134fe4290 + 4, -1, inf) started +[Thread 0] Atomics.wait(0x55d134fe4290 + 4, 0, inf) was woken up by another thread +[Thread 1] Atomics.wait(0x55d134fe4290 + 4, -1, inf) was woken up by another thread +``` + ### `--trace-deprecation` -Print short summaries of calls to `Atomics.wait()` to stderr. +Print short summaries of calls to [`Atomics.wait()`][] to stderr. The output could look like this: ```text @@ -835,6 +835,14 @@ The output could look like this: [Thread 1] Atomics.wait(0x55d134fe4290 + 4, -1, inf) was woken up by another thread ``` +The fields here correspond to: + +- The thread id as given by [`worker_threads.threadId`][] +- The base address of the `SharedArrayBuffer` in question, as well as the + byte offset corresponding to the index passed to `Atomics.wait()` +- The expected value that was passed to `Atomics.wait()` +- The timeout passed to `Atomics.wait` + ### `--trace-deprecation`