Recent Node.js 502 bad gateway issues
In December of 2018, many Node.js users noticed that their applications randomly returned an HTTP status code 502 “Bad Gateway” error. On the IBM Cloud, the affected applications are deployed as Cloud Foundry applications or as Docker containers in Kubernetes clusters.
The Node.js community immediately noticed the issue and recognized it as a regression bug that will affect different LTS runtime versions (6.14.x and 6.15.x, 8.14.x, and 10.14.x). Further information about this bug can be found in this Github issue on Node.js source code.
Immediately the community started to fix this bug. Before the end of 2018, the community released new minor versions which contain the fix. In particular, the minor versions released are 6.16.x, 8.15.x, and 10.15.x.
Steps to take to resolve the issue
If you have been affected by this issue, you can easily resolve it by forcing your application to use a higher Node.js runtime version from your package.json
file.
Here is an example of how to do that:
As you can see, the package.json
file contains pretty much all of the dependencies that you need for your app. The most important section is:
As you know, this section specifies which Node.js runtime version is to be used to run the application. Updating the value of this key with a “good” runtime version (e.g., 6.16.x, 8.15.x, or 10.15.x) will resolve this kind of issues.
If you are pushing your application in IBM Cloud on Cloud Foundry (using cf push APP_NAME
), you could try to use -b
option for setting an older buildpack version, but without changing the Node.js runtime version in package.json
, you could still face the issue.
If you are deploying your application as a Docker container inside an IBM Cloud Kubernetes Service cluster and you are using the official Node.js images, you will not face this issue since you will automatically use always the last minor version for the major version chosen.