apollographql / apollo-client

:rocket:  A fully-featured, production ready caching GraphQL client for every UI framework and GraphQL server.
https://apollographql.com/client
MIT License
19.39k stars 2.66k forks source link

Websockets can't connect through reverse proxy #12045

Open FrancisLLSW opened 2 months ago

FrancisLLSW commented 2 months ago

Hello there, I've encountered a blocker at work with GraphQL subscriptions over WebSockets, and I need some help.

The tech stack in my company requires an Angular front-end to connect to a Dotnet 8 back-end through a Dotnet reverse proxy (YARP, basically using proxy's localhost:[portA] and being redirected to the back-end project's localhost:[portB]).

If I set the back-end project's URL directly, the connection is successful and the subscription works perfectly. But when using the Reverse Proxy URL, Apollo can't establish a WebSocket connection. I'm certain that the Reverse Proxy is allowing those connections correctly because the YARP documentation explicitly states that WebSockets are allowed by default, and I was able to successfuly subscribe to the back-end using Postman (a Chromium-based app) with the Reverse Proxy URL.

Due to the nature of the project, I cannot provide code to replicate my environment, even though the front-end part is the text-book implementation of a GraphQLWsLink with a split link.

I've experienced a very strange behavior regarding this issue: First, a month ago I encountered this problem and spent a few days investigating it. One day, out of desperation, I tried running every troubleshooting agent in Windows that was related to network configurations. Mysteriously, websocket connections were working fine after that! Barely for a month, anyway, and I was never too confident that the troubleshooting did it as none of them found any problems on my PC. The other flabbergasting behavior is the fact that other colleagues have been able to run my code and didn't have any problems with the websockets whatsoever. Same configuration, same everything. Obviously I've tried every possible scenario: admin privileges when building any of the projects, re-installing everything, turning on and off the WebSocket feature in IIS, switched browsers, reinstalled browsers, checked network configurations (even if it's projects running locally). This is worrying me, especially after this month without issues, because I cannot really know if it could happen again to another colleague during development, or even in a production environment.

Over the dozen hours I've been stuck at this, I found this ticket that might be related to my problem, but it was never closed https://github.com/apollographql/apollo-client/issues/8356

Thank you for reading this, and I hope you can point me in the right direction to solve this frustrating mystery.

alessbell commented 2 months ago

Hi @FrancisLLSW 👋 I'm sorry for the frustration - that sounds like quite the mystery and I understand your fear of the issue returning. Were there any notable differences you can share between the environment on your machine and your colleagues' who had no problem running it with the reverse proxy url? Unfortunately without being able to debug in an environment that's reproducing the issue, the best we can do is guess.

FrancisLLSW commented 2 months ago

Hi again, and thanks for the quick answer! As far as we know, we have pretty much the same network configuration and are using the same laptop model with all apps updated at the same time by the company.