denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
96.47k stars 5.33k forks source link

`version 2.0.1` breaks npm:MongoDB compatibility #26413

Open Zizaco opened 5 hours ago

Zizaco commented 5 hours ago

Version: Deno 2.0.1 and 2.0.2 MongoDB Package Version npm:mongodb@^6.9.0

I was working on a project using MongoDB when I learned that there was a new version available (2.0.2). After upgrading, all my tests started failing, as the new version was unable to establish a database connection.

I was able to isolate and reproduce it directly from the repl:

$  atlas deployments list
NAME       TYPE    MDB VER   STATE
cluster0   LOCAL   8.0.1     IDLE

To list both local and cloud Atlas deployments, authenticate to your Atlas account using the "atlas login" command.
$  deno upgrade 2.0.2
Current Deno version: v2.0.0
Downloading https://github.com/denoland/deno/releases/download/v2.0.2/deno-x86_64-unknown-linux-gnu.zip
Deno is upgrading to version 2.0.2

Upgraded successfully to Deno v2.0.2 (stable)

$  deno --version
deno 2.0.2 (stable, release, x86_64-unknown-linux-gnu)
v8 12.9.202.13-rusty
typescript 5.6.2
$  cat deno.json | grep npm:mongo
    "mongodb": "npm:mongodb@^6.9.0"
$  deno
Deno 2.0.2
exit using ctrl+d, ctrl+c, or close()
REPL is running with all permissions allowed.
To specify permissions, run `deno repl` with allow flags.
> import { MongoClient } from "mongodb";
undefined
> const mongoClient = new MongoClient("mongodb://127.0.0.1:27017");
undefined
> await mongoClient.connect() // it takes a few seconds to throw
Uncaught MongoServerSelectionError: connect ECONNREFUSED ::1:27017 - Local (undefined:undefined)
    at Topology.selectServer (file:///home/zizaco/.cache/deno/npm/registry.npmjs.org/mongodb/6.9.0/lib/sdam/topology.js:303:38)
    at eventLoopTick (ext:core/01_core.js:214:9)
    at async Topology._connect (file:///home/zizaco/.cache/deno/npm/registry.npmjs.org/mongodb/6.9.0/lib/sdam/topology.js:196:28)
    at async Topology.connect (file:///home/zizaco/.cache/deno/npm/registry.npmjs.org/mongodb/6.9.0/lib/sdam/topology.js:158:13)
    at async topologyConnect (file:///home/zizaco/.cache/deno/npm/registry.npmjs.org/mongodb/6.9.0/lib/mongo_client.js:209:17)
    at async MongoClient._connect (file:///home/zizaco/.cache/deno/npm/registry.npmjs.org/mongodb/6.9.0/lib/mongo_client.js:222:13)
    at async MongoClient.connect (file:///home/zizaco/.cache/deno/npm/registry.npmjs.org/mongodb/6.9.0/lib/mongo_client.js:147:13)
    at async <anonymous>:1:22
>

BTW, it works perfectly with Deno 2.0.0

$  atlas deployments list
NAME       TYPE    MDB VER   STATE
cluster0   LOCAL   8.0.1     IDLE

To list both local and cloud Atlas deployments, authenticate to your Atlas account using the "atlas login" command.
$  deno upgrade 2.0.0
Current Deno version: v2.0.2
Downloading https://github.com/denoland/deno/releases/download/v2.0.0/deno-x86_64-unknown-linux-gnu.zip
Deno is upgrading to version 2.0.0

Upgraded successfully to Deno v2.0.0 (stable)

$  deno --version
deno 2.0.0 (stable, release, x86_64-unknown-linux-gnu)
v8 12.9.202.13-rusty
typescript 5.6.2
$  cat deno.json | grep npm:mongo
    "mongodb": "npm:mongodb@^6.9.0"
$  deno
Deno 2.0.0
exit using ctrl+d, ctrl+c, or close()
REPL is running with all permissions allowed.
To specify permissions, run `deno repl` with allow flags.
> import { MongoClient } from "mongodb";
undefined
> const mongoClient = new MongoClient("mongodb://127.0.0.1:27017");
undefined
> await mongoClient.connect() // resolves very quickly
<ref *1> MongoClient {
  _events: [Object: null prototype] {},
  _eventsCount: 0,
  _maxListeners: undefined,
  mongoLogger: undefined,
  s: {
    url: "mongodb://127.0.0.1:27017",
  }
  # [...]
} 
>
# success. All other db operations work (transactions, change streams, crud)
Zizaco commented 4 hours ago

The same issue occurs with Deno 2.0.1. Only v2.0.0 works.

$  deno upgrade 2.0.1
Current Deno version: v2.0.0
Downloading https://github.com/denoland/deno/releases/download/v2.0.1/deno-x86_64-unknown-linux-gnu.zip
Deno is upgrading to version 2.0.1

Upgraded successfully to Deno v2.0.1 (stable)

$  deno
Deno 2.0.1
exit using ctrl+d, ctrl+c, or close()
REPL is running with all permissions allowed.
To specify permissions, run `deno repl` with allow flags.
> import { MongoClient } from "mongodb";
undefined
> const mongoClient = new MongoClient("mongodb://127.0.0.1:27017");
undefined
> await mongoClient.connect() // it takes a few seconds to throw
Uncaught MongoServerSelectionError: Cannot read properties of undefined (reading 'setNoDelay')
    at Topology.selectServer (file:///home/zizaco/.cache/deno/npm/registry.npmjs.org/mongodb/6.9.0/lib/sdam/topology.js:303:38)
    at eventLoopTick (ext:core/01_core.js:214:9)
    at async Topology._connect (file:///home/zizaco/.cache/deno/npm/registry.npmjs.org/mongodb/6.9.0/lib/sdam/topology.js:196:28)
    at async Topology.connect (file:///home/zizaco/.cache/deno/npm/registry.npmjs.org/mongodb/6.9.0/lib/sdam/topology.js:158:13)
    at async topologyConnect (file:///home/zizaco/.cache/deno/npm/registry.npmjs.org/mongodb/6.9.0/lib/mongo_client.js:209:17)
    at async MongoClient._connect (file:///home/zizaco/.cache/deno/npm/registry.npmjs.org/mongodb/6.9.0/lib/mongo_client.js:222:13)
    at async MongoClient.connect (file:///home/zizaco/.cache/deno/npm/registry.npmjs.org/mongodb/6.9.0/lib/mongo_client.js:147:13)
    at async <anonymous>:1:22
>
marvinhagemeister commented 3 hours ago

@Zizaco FYI: The Cannot read properties of undefined (reading 'setNoDelay') is fixed in 2.0.2. It was a regression and the reason we pulled 2.0.1