Bug in Javascript client SDK and cloud error

Specifications

  • Client Version: Latest NPM version 1.33.2
  • InfluxDB Version: Influx Cloud, powered by TSM, storage engine V2, on AWS (free account)
  • Platform: Node version 20.11.1 - issue occurs on both Windows and Linux clients

Code sample to reproduce problem

   var writeAPI;

    try {
        writeAPI = influxdb.getWriteApi(influxConfig.org,influxConfig.bucket)
        writeAPI.writePoint(point)
        writeAPI.flush()
    }
    catch(e) {
        console.error(e)
    }
    finally {
        try {
            if(writeAPI != undefined)
                writeAPI.close()
        }
        catch(eClose) {
            console.error(eClose)
        }
    }

Expected behavior

I would assume that if there was a write error, that it would be caught. It’s actually surprising how often Influx cloud throws 503 (service unavailable) errors.

Actual behavior

Here is the error that is thrown, and the Node.js process exits when this error occurs.

ERROR: Write to InfluxDB failed. m [HttpError]: 503 Service Unavailable : upstream connect error or disconnect/reset before headers. reset reason: connection termination
at IncomingMessage. (/home/rick/uberbroker/node_modules/@influxdata/influxdb-client/dist/index.js:5:5671)
at IncomingMessage.emit (node:events:530:35)
at endReadableNT (node:internal/streams/readable:1696:12)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
statusCode: 503,
statusMessage: ‘Service Unavailable’,
body: ‘upstream connect error or disconnect/reset before headers. reset reason: connection termination’,
contentType: ‘text/plain’,
_retryAfter: 0
}
node:internal/process/promises:289
triggerUncaughtException(err, true /* fromPromise */);
^

m [HttpError]: 503 Service Unavailable : upstream connect error or disconnect/reset before headers. reset reason: connection termination
at IncomingMessage. (/home/rick/uberbroker/node_modules/@influxdata/influxdb-client/dist/index.js:5:5671)
at IncomingMessage.emit (node:events:530:35)
at endReadableNT (node:internal/streams/readable:1696:12)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
statusCode: 503,
statusMessage: ‘Service Unavailable’,
body: ‘upstream connect error or disconnect/reset before headers. reset reason: connection termination’,
contentType: ‘text/plain’,
_retryAfter: 0
}

Node.js v20.11.1

Additional info

This happens multiple times per day, and does not appear to be a catchable error. I’m curious:

  1. why 503 errors happen so often on a hosted service
  2. why this exception isn’t caught - seems like a client bug

You are not the only one reporting this, let me see if i can find anyone to help with this. Just to confirm you are on this client library correct?

I found a solution - I needed to add the “await” keyword on the async functions in the writeAPI (flush and close).

1 Like

Id like to add this to the docs then, just to confirm it was the v2 version of the js library?

Well, technically it is release 1.33.2 of the Influx 2.0 library. It’s whatever version is in NPM (and the Github repo also shows the latest release as 1.33.2, released Feb 23, 2023)