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:

{
  "name": "get-started-node",
  "main": "server.js",
  "description": "An introduction to developing Node.js apps on the Bluemix platform",
  "version": "0.1.1",
  "private": false,
  "engines": {
    "node": "^7.10.0"
  },
  "scripts": {
    "start": "node server.js"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/IBM-Bluemix/get-started-node"
  },
  "dependencies": {
    "@dynatrace/oneagent": "^1.137.152-1.0.0",
    "body-parser": "^1.17.x",
    "cfenv": "^1.0.x",
    "cloudant": "1.9.x",
    "dotenv": "^4.0.0",
    "express": "^4.15.x",
    "npm": "^6.4.1",
    "semver": "^5.6.0"
  },
  "author": "IBM Corp",
  "license": "Apache-2.0"
}

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:

"engines": {
    "node": "^7.10.0"
}

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.

Was this article helpful?
YesNo

More from Cloud

Enhance your data security posture with a no-code approach to application-level encryption

4 min read - Data is the lifeblood of every organization. As your organization’s data footprint expands across the clouds and between your own business lines to drive value, it is essential to secure data at all stages of the cloud adoption and throughout the data lifecycle. While there are different mechanisms available to encrypt data throughout its lifecycle (in transit, at rest and in use), application-level encryption (ALE) provides an additional layer of protection by encrypting data at its source. ALE can enhance…

Attention new clients: exciting financial incentives for VMware Cloud Foundation on IBM Cloud

4 min read - New client specials: Get up to 50% off when you commit to a 1- or 3-year term contract on new VCF-as-a-Service offerings, plus an additional value of up to USD 200K in credits through 30 June 2025 when you migrate your VMware workloads to IBM Cloud®.1 Low starting prices: On-demand VCF-as-a-Service deployments begin under USD 200 per month.2 The IBM Cloud benefit: See the potential for a 201%3 return on investment (ROI) over 3 years with reduced downtime, cost and…

The history of the central processing unit (CPU)

10 min read - The central processing unit (CPU) is the computer’s brain. It handles the assignment and processing of tasks, in addition to functions that make a computer run. There’s no way to overstate the importance of the CPU to computing. Virtually all computer systems contain, at the least, some type of basic CPU. Regardless of whether they’re used in personal computers (PCs), laptops, tablets, smartphones or even in supercomputers whose output is so strong it must be measured in floating-point operations per…

IBM Newsletters

Get our newsletters and topic updates that deliver the latest thought leadership and insights on emerging trends.
Subscribe now More newsletters