Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing deadlock between node and python await. #504

Merged
merged 12 commits into from
Jun 19, 2024
2 changes: 1 addition & 1 deletion .github/workflows/linux-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
fetch-depth: 0

- name: Install, build and run tests
run: ./docker-compose.sh test
run: ./docker-compose.sh build
env:
METACALL_BUILD_TYPE: ${{ matrix.build }}
METACALL_BASE_IMAGE: ${{ matrix.image }}
15 changes: 9 additions & 6 deletions source/loaders/node_loader/bootstrap/lib/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,29 @@ const path = require('path');
const util = require('util');
const fs = require('fs');

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

const node_require = Module.prototype.require;
const node_resolve = require.resolve;
const node_cache = require.cache;

/* Store in the module prototype the original functions for future use in derived loaders like TypeScript */
// Store in the module prototype the original functions for future use in derived loaders like TypeScript
Module.prototype.node_require = node_require;
Module.prototype.node_resolve = node_resolve;
Module.prototype.node_cache = node_cache;

function node_loader_trampoline_initialize(loader_library_path) {
// Restore the argv (this is used for tricking node::Start method)
process.argv = [ process.argv[0] ];

// Add current execution directory to the execution paths
node_loader_trampoline_execution_path(process.cwd());

const paths = [
/* Local version of MetaCall NodeJS Port */
// Local version of MetaCall NodeJS Port
'metacall',
/* Optionally, use loader library path for global installed NodeJS Port */
// Optionally, use loader library path for global installed NodeJS Port
...loader_library_path ? [ path.join(loader_library_path, 'node_modules', 'metacall', 'index.js') ] : [],
];

Expand Down Expand Up @@ -333,7 +336,7 @@ function node_loader_trampoline_discover(handle) {
}

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

/* Get trampoline from list of linked bindings */
// Get trampoline from list of linked bindings
const trampoline = process._linkedBinding('node_loader_trampoline_module');

const node_loader_ptr = trampoline.register(impl, ptr, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ NODE_LOADER_NO_EXPORT void node_loader_impl_exception(napi_env env, napi_status

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

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);

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);

NODE_LOADER_NO_EXPORT napi_value node_loader_impl_value_to_napi(loader_impl_node node_impl, napi_env env, value arg);
Expand Down
Loading
Loading