NPM proxy requests failing with 502 errors while backend services remain operational

I’m experiencing an odd issue where my NPM configuration keeps returning 502 errors for all requests being proxied. The bizarre thing is that my backend services are functioning perfectly well. I can reach them directly through their IPs and ports without any hassle, even from within the NPM Docker container.

This issue appears to occur sporadically. It vanished for about thirty minutes before resurfacing again. I’ve noticed some related discussions on GitHub, but most resolutions suggest starting over from scratch. I’m really hoping someone here can shed light on the actual cause and provide a better solution.

Has anyone faced this issue? What might be the reason for NPM losing connection to functioning services?

Had this exact issue about six months ago - turned out to be a memory leak in NPM itself. Proxy works fine at first, then slowly degrades until you get 502s even though the backend’s still up. I fixed it by setting up a cron job to restart the NPM container every 24 hours. Not pretty, but it completely stopped the random failures. Check your NPM container’s memory usage when it’s working vs when it starts failing. Mine would hit around 80% memory before the proxy went unreliable.

This screams timeout issues. Had the exact same problem last year - NPM randomly throwing 502s even though backends were fine. Turned out to be proxy timeout settings too aggressive + network latency spikes. Bump your proxy_connect_timeout and proxy_read_timeout in the advanced tab. I changed mine from defaults to 300 seconds each and the random 502s vanished. The sporadic thing you’re describing is exactly what I saw - NPM worked fine until a backend took slightly longer than expected to respond.

sounds like a dns issue to me. i had a similar prob where npm couldn’t resolve hosts even though everything else was working. maybe try using ip addresses in your proxy config for now? and check your docker network. sometimes containers lose connection unexpectedly.