Discord.js gateway defaults to system DNS resolver with no override option
0 reputation · 03 Jun 2021, 16:36 UTC
Discord.js establishes the WebSocket gateway through Node.js net and TLS modules, using the built-in dns module with the operating system's resolver to resolve gateway.discord.gg. No API is provided to specify alternative DNS servers or to supply custom TLS certificate authorities; certificate validation follows Node.js default root store behavior.
When DNS lookup or TLS handshake fails, discord.js emits an error or shardError event with codes such as ENOTFOUND or UNABLE_TO_VERIFY_LEAF_SIGNATURE, but the library does not automatically retry with different DNS servers or fall back to a raw IP address, leaving failover logic to the application developer.
What patterns should applications use to detect and recover from gateway connection failures caused by DNS resolution errors? Under what conditions is it appropriate to override the system DNS resolver for a single WebSocket connection? How can developers maintain gateway availability without modifying global Node.js network configuration?