Skip to content

Commit 02c7f28

Browse files
authored
Merge pull request #504 from metacall/fix/node-python-await-deadlock
Fixing deadlock between node and python await.
2 parents 9a911d4 + 9915642 commit 02c7f28

File tree

14 files changed

+651
-187
lines changed

14 files changed

+651
-187
lines changed

.github/workflows/linux-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
fetch-depth: 0
3232

3333
- name: Install, build and run tests
34-
run: ./docker-compose.sh test
34+
run: ./docker-compose.sh build
3535
env:
3636
METACALL_BUILD_TYPE: ${{ matrix.build }}
3737
METACALL_BASE_IMAGE: ${{ matrix.image }}

source/loaders/node_loader/bootstrap/lib/bootstrap.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,29 @@ const path = require('path');
66
const util = require('util');
77
const fs = require('fs');
88

9-
/* Require the JavaScript parser */
9+
// Require the JavaScript parser
1010
const espree = require(path.join(__dirname, 'node_modules', 'espree'));
1111

1212
const node_require = Module.prototype.require;
1313
const node_resolve = require.resolve;
1414
const node_cache = require.cache;
1515

16-
/* Store in the module prototype the original functions for future use in derived loaders like TypeScript */
16+
// Store in the module prototype the original functions for future use in derived loaders like TypeScript
1717
Module.prototype.node_require = node_require;
1818
Module.prototype.node_resolve = node_resolve;
1919
Module.prototype.node_cache = node_cache;
2020

2121
function node_loader_trampoline_initialize(loader_library_path) {
22+
// Restore the argv (this is used for tricking node::Start method)
23+
process.argv = [ process.argv[0] ];
24+
2225
// Add current execution directory to the execution paths
2326
node_loader_trampoline_execution_path(process.cwd());
2427

2528
const paths = [
26-
/* Local version of MetaCall NodeJS Port */
29+
// Local version of MetaCall NodeJS Port
2730
'metacall',
28-
/* Optionally, use loader library path for global installed NodeJS Port */
31+
// Optionally, use loader library path for global installed NodeJS Port
2932
...loader_library_path ? [ path.join(loader_library_path, 'node_modules', 'metacall', 'index.js') ] : [],
3033
];
3134

@@ -333,7 +336,7 @@ function node_loader_trampoline_discover(handle) {
333336
}
334337

335338
function node_loader_trampoline_test(obj) {
336-
/* Imporant: never trigger an async resource in this function */
339+
// Imporant: never trigger an async resource in this function
337340
if (obj !== undefined) {
338341
fs.writeSync(process.stdout.fd, `${util.inspect(obj, false, null, true)}\n`);
339342
}
@@ -411,7 +414,7 @@ module.exports = ((impl, ptr) => {
411414
throw new Error('Process arguments (process.argv[2], process.argv[3]) not defined.');
412415
}
413416

414-
/* Get trampoline from list of linked bindings */
417+
// Get trampoline from list of linked bindings
415418
const trampoline = process._linkedBinding('node_loader_trampoline_module');
416419

417420
const node_loader_ptr = trampoline.register(impl, ptr, {

source/loaders/node_loader/include/node_loader/node_loader_impl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ NODE_LOADER_NO_EXPORT void node_loader_impl_exception(napi_env env, napi_status
5555

5656
NODE_LOADER_NO_EXPORT void node_loader_impl_finalizer(napi_env env, napi_value v, void *data);
5757

58+
NODE_LOADER_NO_EXPORT napi_value node_loader_impl_promise_await(loader_impl_node node_impl, napi_env env, const char *name, value *args, size_t size);
59+
5860
NODE_LOADER_NO_EXPORT value node_loader_impl_napi_to_value(loader_impl_node node_impl, napi_env env, napi_value recv, napi_value v);
5961

6062
NODE_LOADER_NO_EXPORT napi_value node_loader_impl_value_to_napi(loader_impl_node node_impl, napi_env env, value arg);

0 commit comments

Comments
 (0)