mongodb-memory-server: server.unref is not a function. (In 'server.unref()', 'server.unref' is undefined)
Versions
- Bun: 1.0.3
- mongodb-memory-server-*: ^9.0.0-beta.2
- mongodb(the binary version): ^6.1.0
- mongodb(the js package): 0.0.0
- mongoose: 7.5.2
- system: MacOS
package: mongo-memory-server
What is the Problem?
Looks like a problem with the port, but I didn’t specified one.
Code Example
My repo: https://github.com/DWboutin/kiosq-backend
It’s the only thing implemented
Debug Output
Debug Output
src/features/users/__tests__/UserRepository.spec.ts:
MongoMS:ResolveConfig Debug Mode Enabled, through Environment Variable +0ms
MongoMS:ResolveConfig findPackageJson: Found package.json at "/Users/mikaelboutin/Desktop/coding/bun-backend/package.json" +1ms
MongoMS:MongoMemoryServer create: Called .create() method +0ms
MongoMS:MongoMemoryServer Mongo[unknown]: start: Called .start() method +0ms
MongoMS:MongoMemoryServer Mongo[unknown]: _startUpInstance: Called MongoMemoryServer._startUpInstance() method +0ms
MongoMS:MongoMemoryServer Mongo[unknown]: getStartOptions: forceSamePort: false +1ms
MongoMS:MongoMemoryServer Mongo[unknown]: _startUpInstance threw a Error: [TypeError: server.unref is not a function. (In 'server.unref()', 'server.unref' is undefined)] +1ms
MongoMS:MongoMemoryServer Mongo[unknown]: stop: Called .stop() method +0ms
MongoMS:MongoMemoryServer Mongo[unknown]: stop: "instanceInfo" is not defined (never ran?) +0ms
80 | function tryPort(port) {
81 | return new Promise((res, rej) => {
82 | const server = http.createServer();
83 | server.unref(); // dont keep this server from exiting the application
84 | server.on('error', (err) => {
85 | if (err?.code !== 'EADDRINUSE') {
^
TypeError: server.unref is not a function. (In 'server.unref()', 'server.unref' is undefined)
at /Users/mikaelboutin/Desktop/coding/bun-backend/node_modules/mongodb-memory-server-core/lib/util/getport/index.js:85:21
Do you know why it happenes?
no
About this issue
- Original URL
- State: closed
- Created 9 months ago
- Comments: 16
Commits related to this issue
- fix(getport): only run ".unref" if it exists fixes #801 — committed to nodkz/mongodb-memory-server by hasezoey 9 months ago
🎉 This issue has been resolved in version 9.0.0-beta.3 🎉
The release is available on:
Your semantic-release bot 📦🚀
i will re-open this issue to keep some tracker for the
.unref
check (and maybe extend until the childprocess issue is resolved)i have made https://github.com/nodkz/mongodb-memory-server/issues/802, which tracks this “state” addition, but ultimately this does not really affect how the cleanup (and so the cleanup error) came to be and seems to be harmless aside from duplicate execution (at least for this case)
firstly,
.stop
automatically calls.cleanup
, with options{ doCleanup: true, force: false }
(ie clean temporary data, if not user specified), second is that.cleanup
is a async function, so it would be awaitedyou can fix this with either:
.cleanup
call, or.stop({ doCleanup: false })
as for why
stop
is seemingly called twice, i now know why after looking at the log again:.stop
is always called if there is ainstanceError
eventi will likely need to add some kind of tracker to not accidentally call
.stop
twicea port is always required, if you dont specify one, one will be generated
this is a problem with bun, seems like it does not implement
net:server:unref
, see bun documentation:source
Not a problem with MMS and
bun
is also not officially supported by MMS, please open a issue withbun
instead (deno somewhat recently had added this)