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

Unable to use http cluster with bazel #227

Closed
kalbasit opened this issue Jun 12, 2018 · 3 comments · Fixed by #1515
Closed

Unable to use http cluster with bazel #227

kalbasit opened this issue Jun 12, 2018 · 3 comments · Fixed by #1515

Comments

@kalbasit
Copy link
Contributor

kalbasit commented Jun 12, 2018

We currently have an HTTP server build using nodejs cluster. When we call fork it blows up because it's looking for the binary at the wrong place.

$ git clone https://github.com/kalbasit/bazel-reproducible.git
$ cd bazel-reproducible/http-cluster-does-not-work
$ bazel run //server:http
WARNING: ignoring _JAVA_OPTIONS in environment.
INFO: Analysed target //server:http (0 packages loaded).
INFO: Found 1 target...
Target //server:http up-to-date:
  bazel-bin/server/http_bin.sh
  bazel-bin/server/http
INFO: Elapsed time: 0.728s, Critical Path: 0.04s
INFO: 0 processes.
INFO: Build completed successfully, 1 total action

INFO: Running command line: bazel-bin/server/http
WARNING: source-map-support module not installed.
   Stack traces from languages like TypeScript will point to generated .js files.

[server-1528846565034] Starting master
[server-1528846565034] listening on :8080
[server-1528846565034] Cluster options: {
    "count": 8,
    "name": "server-1528846565034"
}
[server-1528846565034] starting worker thread
[server-1528846565034] starting worker thread
[server-1528846565034] starting worker thread
[server-1528846565034] starting worker thread
[server-1528846565034] starting worker thread
[server-1528846565034] starting worker thread
[server-1528846565034] starting worker thread
module.js:549
    throw err;
    ^

Error: Cannot find module '/home/kalbasit/.cache/bazel/_bazel_kalbasit/727d60ccb89e565dc5ed6e14ea3a46c6/execroot/com_github_kalbasit_bazel/bazel-out/k8-fastbuild/bin/server/http.runfiles/com_github_kalbasit_bazel/com_github_kalbasit_bazel/server/http.js'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:188:16)
    at bootstrap_node.js:609:3
[server-1528846565034] starting worker thread
[server-1528846565034] Worker 32525 died
[server-1528846565034] starting worker thread
module.js:549
    throw err;
    ^

It's trying to find the module at

/home/kalbasit/.cache/bazel/_bazel_kalbasit/727d60ccb89e565dc5ed6e14ea3a46c6/execroot/com_github_kalbasit_bazel/bazel-out/k8-fastbuild/bin/server/http.runfiles/com_github_kalbasit_bazel/com_github_kalbasit_bazel/server/http.js

But the module actually lives at

/home/kalbasit/.cache/bazel/_bazel_kalbasit/727d60ccb89e565dc5ed6e14ea3a46c6/execroot/com_github_kalbasit_bazel/bazel-out/k8-fastbuild/bin/server/http.runfiles/com_github_kalbasit_bazel/server/http.js

Notice the double com_github_kalbasit_bazel (that's the workspace name).

I've put together a reproducible example here.

@alexeagle are you able to reproduce? Is this a BUG in rules_nodejs or in my code?

@kalbasit
Copy link
Contributor Author

kalbasit commented Jun 13, 2018

@alexeagle I've put a console.log in the node_loader.js at this line. I see the console.log when I start the server, but when fork() is called, it does not use this function for loading the file. I believe that's the root cause of the issue.

$ diff -Naur bazel-bin/server/http_bin_loader.js{.bak,}
--- bazel-bin/server/http_bin_loader.js.bak     2018-06-13 14:46:44.701734959 -0700
+++ bazel-bin/server/http_bin_loader.js 2018-06-13 14:46:42.531734975 -0700
@@ -220,6 +220,7 @@
 var originalResolveFilename = module.constructor._resolveFilename;
 module.constructor._resolveFilename =
     function(request, parent) {
+  console.log(`module.constructor._resolveFilename(${JSON.stringify(request)})`);
   var failedResolutions = [];
   var resolveLocations = [
     request,
$ bazel-bin/server/http
module.constructor._resolveFilename("source-map-support")
WARNING: source-map-support module not installed.
   Stack traces from languages like TypeScript will point to generated .js files.

module.constructor._resolveFilename("com_github_kalbasit_bazel/server/http.js")
module.constructor._resolveFilename("com_github_kalbasit_bazel/server/cluster")
module.constructor._resolveFilename("cluster")
module.constructor._resolveFilename("os")
module.constructor._resolveFilename("com_github_kalbasit_bazel/server/server")
module.constructor._resolveFilename("com_github_kalbasit_bazel/server/lib")
[server-1528926301026] Starting master
[server-1528926301026] listening on :8080
[server-1528926301026] Cluster options: {
    "count": 8,
    "name": "server-1528926301026"
}
[server-1528926301026] starting worker thread
[server-1528926301026] starting worker thread
[server-1528926301026] starting worker thread
[server-1528926301026] starting worker thread
[server-1528926301026] starting worker thread
[server-1528926301026] starting worker thread
[server-1528926301026] starting worker thread
[server-1528926301026] starting worker thread
module.js:549
    throw err;
    ^

Error: Cannot find module '/home/kalbasit/code/personal/base/src/github.com/kalbasit/bazel-reproducible/http-cluster-does-not-work/com_github_kalbasit_bazel/server/http.js'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:188:16)
    at bootstrap_node.js:609:3
module.js:549
    throw err;
    ^

@alexeagle any pointers on how to fix this?

@alexeagle
Copy link
Collaborator

@gregmagolan worked recently on how node programs under Bazel find the same node binary when calling out to another node process. This seems slightly different since it's failing in module resolution after forking another process.

@Toxicable
Copy link

This will be solved when nodejs_binary uses the linker by default

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants