getappmap/appmap-agent-js

ERR_DLOPEN_FAILED in Docker Compose dev environment

Closed this issue · 2 comments

Hey all, I'm getting the following error when trying to run the AppMap agent in a Docker Compose dev environment:

api-stonefruit-api-1  | > @stonefruit/api@0.1.0 dev:apiContainer
api-stonefruit-api-1  | > npx appmap-agent-js -- node /app/build/main.js
api-stonefruit-api-1  |
api-stonefruit-api-1  | (node:44) ExperimentalWarning: Custom ESM Loaders is an experimental feature. This feature could change at any time
api-stonefruit-api-1  | (Use `node --trace-warnings ...` to show where the warning was created)
api-stonefruit-api-1  |
api-stonefruit-api-1  | [appmap@12.1.2] Detected an unknown error. If this error disapear when not recording your application, it is probably an issue within the appmap framework. If this is
the case, please consider submitting a bug report at:
api-stonefruit-api-1  |   https://github.com/getappmap/appmap-agent-js/issues
api-stonefruit-api-1  |
api-stonefruit-api-1  | node:internal/modules/cjs/loader:1243
api-stonefruit-api-1  |   return process.dlopen(module, path.toNamespacedPath(filename));
api-stonefruit-api-1  |                  ^
api-stonefruit-api-1  |
api-stonefruit-api-1  | Error: /app/node_modules/posix-socket/build/Release/addon.node: invalid ELF header
api-stonefruit-api-1  |     at Module._extensions..node (node:internal/modules/cjs/loader:1243:18)
api-stonefruit-api-1  |     at Module.load (node:internal/modules/cjs/loader:1037:32)
api-stonefruit-api-1  |     at Module._load (node:internal/modules/cjs/loader:878:12)
api-stonefruit-api-1  |     at Module.require (node:internal/modules/cjs/loader:1061:19)
api-stonefruit-api-1  |     at require (node:internal/modules/cjs/helpers:103:18)
api-stonefruit-api-1  |     at Object.<anonymous> (/app/node_modules/posix-socket/lib/main.js:1:18)
api-stonefruit-api-1  |     at Module._compile (node:internal/modules/cjs/loader:1159:14)
api-stonefruit-api-1  |     at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
api-stonefruit-api-1  |     at Module.load (node:internal/modules/cjs/loader:1037:32)
api-stonefruit-api-1  |     at Module._load (node:internal/modules/cjs/loader:878:12) {
api-stonefruit-api-1  |   code: 'ERR_DLOPEN_FAILED'
api-stonefruit-api-1  | }
api-stonefruit-api-1  |
api-stonefruit-api-1  | Node.js v18.12.1

I think I understand what's going on here - the posix-socket module version (which I believe is a dependency of AppMap) is being installed for MacOS when I install it locally, but when I try to run it in a Docker container, the ELF headers are expected to be different.

There are a few similar issues out there, notably with bcrypt, and the solution is to run npm install inside of the Docker container rather than on the host machine so it installs the correct version. However, this really only helps when you're building your container. In development, where the project directory (including node_modules) is often mounted as a volume in a running container, there's not an easy way around this. At least not that I've found.

It's not necessarily your problem to solve as it's related to my dev environment, but I think my setup is fairly common so this may be something to look at in the future.

Anyway, I wanted to report this mostly in case others run into the same issue. If there's a better place to put troubleshooting information I'd be happy to write this up in a bit more detail and post it there instead, just let me know.

Thanks for all your work on AppMap, seems like a really cool project and I'm enjoying using it so far!

@pbzona thanks for the report! The best to make your node folder portable is to add the following to your appmap.yml configuration file:

socket: net

That makes the agent use node:net instead of posix-socket. Could you tell me if this works so that I can close this issue?

Thanks @lachrist! That seems to have solved it - appreciate the help!