Skip to content

Conversation

aqrln
Copy link
Member

@aqrln aqrln commented Nov 11, 2021

Unless a different IP or hostname is specified using the --host
command-line option, the query engine server binds to 127.0.0.1:

The BinaryEngine client tried to connect to the query engine server
using the localhost hostname, which normally resolves to either
127.0.0.1 or ::1 (and in exotic cases might even resolve to
something completely different). When localhost resolved to the IPv6
loopback address (which seems to be usually the case with Node.js 17),
the client couldn't connect because the query engine server doesn't bind
to it. This commit changes localhost to 127.0.0.1 to avoid this
error.

Fixes #9903

Unless a different IP or hostname is specified using the `--host`
command-line option, the query engine server binds to `127.0.0.1`:

* https://github.com/prisma/prisma-engines/blob/af993bb6d5c28f94e4ab70f68ff69364b628af97/query-engine/query-engine/src/opt.rs#L44-L46
* https://github.com/prisma/prisma-engines/blob/af993bb6d5c28f94e4ab70f68ff69364b628af97/query-engine/query-engine/src/server/mod.rs#L93

The BinaryEngine client tried to connect to the query engine server
using the `localhost` hostname, which normally resolves to either
`127.0.0.1` or `::1` (and in exotic cases might even resolve to
something completely different). When `localhost` resolved to the IPv6
loopback address (which seems to be usually the case with Node.js 17),
the client couldn't connect because the query engine server doesn't bind
to it.  This commit changes `localhost` to `127.0.0.1` to avoid this
error.

Fixes #9903
@aqrln aqrln requested review from Jolg42 and millsp as code owners November 11, 2021 12:50
@aqrln aqrln added this to the 3.5.0 milestone Nov 11, 2021
@Jolg42
Copy link
Contributor

Jolg42 commented Nov 11, 2021

@aqrln looks good!

Harshit was unable to reproduce though #9903 (comment)

Did you get to a reproduction?

@aqrln
Copy link
Member Author

aqrln commented Nov 11, 2021

@Jolg42 on my machine it's reproducible, yes

@aqrln
Copy link
Member Author

aqrln commented Nov 11, 2021

Minimal reproduction:

prisma/packages/client on  aqrln/use-ipv4-loopback-address [$!?] is 📦 v0.0.0 via  v16.5.0
❯ nvm use 16
Now using node v16.5.0 (npm v7.19.1)

prisma/packages/client on  aqrln/use-ipv4-loopback-address [$!?] is 📦 v0.0.0 via  v16.5.0
❯ node
Welcome to Node.js v16.5.0.
Type ".help" for more information.
> dns.lookup('localhost', console.log)
GetAddrInfoReqWrap {
  callback: [Function: log],
  family: 0,
  hostname: 'localhost',
  oncomplete: [Function: onlookup]
}
> null 127.0.0.1 4

>

prisma/packages/client on  aqrln/use-ipv4-loopback-address [$!?] is 📦 v0.0.0 via  v16.5.0 took 19s
❯ nvm use 17
Now using node v17.1.0 (npm v8.1.3)

prisma/packages/client on  aqrln/use-ipv4-loopback-address [$!?] is 📦 v0.0.0 via  v17.1.0
❯ node
Welcome to Node.js v17.1.0.
Type ".help" for more information.
> dns.lookup('localhost', console.log)
GetAddrInfoReqWrap {
  callback: [Function: log],
  family: 0,
  hostname: 'localhost',
  oncomplete: [Function: onlookup]
}
> null ::1 6

>

@Jolg42 Jolg42 merged commit 08808b3 into main Nov 11, 2021
@Jolg42 Jolg42 deleted the aqrln/use-ipv4-loopback-address branch November 11, 2021 20:28
JaavLex added a commit to epfl-si/lhd.graphql that referenced this pull request Mar 1, 2022
- Improves security.
- Works around mistakenly using iPV6 instead of iPV4 (prisma/prisma#10211

* That bug is still somewhat unfixed, it's just a workaround like said earlier.
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 this pull request may close these issues.

Prisma Client: Query Engine engineType=binary incompatible with Node.js v17?
3 participants