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

GraphQL subscription does not work reliably unless listening on 0.0.0.0 #875

Closed
andreialecu opened this issue Sep 27, 2022 · 6 comments
Closed

Comments

@andreialecu
Copy link
Contributor

I've been migrating a NestJS app from Apollo to Mercurius and found that the GraphQL WebSocket endpoint was not working. No connection could be established.

Upon some further inspection, I found that I needed to listen specifically on an explicit IP.

I was able to get things to work initially by specifying 127.0.0.1 as the bound IP address. However, once deployed via docker, this wouldn't work properly.

Instead, I need to specify 0.0.0.0 as mentioned in this comment: #838 (comment)

I wonder why this is necessary. Is it a bug? If not, I haven't seen it documented anywhere.

Related:
#838
nestjs/nest#9903 (comment)
nestjs/graphql#2365

@mcollina
Copy link
Collaborator

It's documented here: https://www.fastify.io/docs/latest/Reference/Server/#listen.

Note that we do not have the resources to support Nest.js users. Please refer to the Nest Discord channel (support) for such questions.

@andreialecu
Copy link
Contributor Author

@mcollina I see, thanks. I missed that doc page. However the default seems to imply that by default it uses localhost which listens on both ipv4 and ipv6, but that doesn't seem to be the case for websocket connections.

For regular HTTP connections, the documentation seems correct. But the websocket server does NOT seem to start on my computer on ipv4/127.0.0.1 unless I explicitly specify either 0.0.0.0 or 127.0.0.1. The documentation implies both ipv4 and ipv6 should start by default.

I'd like to reiterate that this seems to be websocket specific.

@andreialecu
Copy link
Contributor Author

In particular, Chrome is not able to establish a connection when developing locally unless I either use :: or 0.0.0.0 or 127.0.0.1.

Screenshot 2022-09-27 at 13 32 16

@mcollina
Copy link
Collaborator

Are you using the latest version of Fastify? This looks like te problem we fixed in fastify/fastify#4190.

I'll be happy to look into this given a simple repro, ideally just with Fastify and Fastify-websockets

@mcollina
Copy link
Collaborator

This looks like some sort of DNS or networking issue on your machine. What does localhost resolves to?

@andreialecu
Copy link
Contributor Author

➜ yarn why fastify             
├─ @nestjs/platform-fastify@npm:9.0.11
│  └─ fastify@npm:4.4.0 (via npm:4.4.0)
│
├─ @nestjs/platform-fastify@npm:9.0.11 [fc2e5]
│  └─ fastify@npm:4.4.0 (via npm:4.4.0)
│
└─ ...actual-project...
   └─ fastify@npm:4.5.3 (via npm:^4.5.3)

Oh, thank you. Indeed the version of @nestjs/platform-fastify I was using had a previous version of fastify pinned.

➜ yarn why fastify                
├─ @nestjs/platform-fastify@npm:9.1.2
│  └─ fastify@npm:4.6.0 (via npm:4.6.0)
│
├─ @nestjs/platform-fastify@npm:9.1.2 [fc2e5]
│  └─ fastify@npm:4.6.0 (via npm:4.6.0)
│
└─ ...actual-project...
   └─ fastify@npm:4.6.0 (via npm:^4.5.3)

After bumping everything, it's all good. Sorry for taking your time, and thanks for pointing me in the right direction!

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

No branches or pull requests

2 participants