# Bug in Javascript client SDK and cloud error

**URL:** <https://community.influxdata.com/t/bug-in-javascript-client-sdk-and-cloud-error/33620>\
**Category:** Client SDKs\
**Tags:** influxdb, client-libraries, javascript\
**Created:** [March 18, 2024, 7:25pm UTC](https://community.influxdata.com/t/bug-in-javascript-client-sdk-and-cloud-error/33620 "2024-03-18T19:25:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![RickBullotta](https://avatars.discourse-cdn.com/v4/letter/r/779978/32.png) [@RickBullotta](https://community.influxdata.com/u/RickBullotta)\
**Post date:** [March 18, 2024, 7:25pm UTC](https://community.influxdata.com/t/bug-in-javascript-client-sdk-and-cloud-error/33620/1 "2024-03-18T19:25:01Z")

</div>

### 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

```auto
   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](https://community.influxdata.com/groups/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](https://community.influxdata.com/groups/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

---

<div class="post-metadata">

**Author:** ![Zoe\_Steinkamp](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/zoe_steinkamp/32/13300_2.png) [@Zoe\_Steinkamp](https://community.influxdata.com/u/Zoe_Steinkamp)\
**Post date:** [March 19, 2024, 4:30pm UTC](https://community.influxdata.com/t/bug-in-javascript-client-sdk-and-cloud-error/33620/2 "2024-03-19T16:30:05Z")

</div>

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?

> **[GitHub - influxdata/influxdb-client-js: InfluxDB 2.0 JavaScript client](https://github.com/influxdata/influxdb-client-js)**
>
> InfluxDB 2.0 JavaScript client. Contribute to influxdata/influxdb-client-js development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![RickBullotta](https://avatars.discourse-cdn.com/v4/letter/r/779978/32.png) [@RickBullotta](https://community.influxdata.com/u/RickBullotta)\
**Post date:** [March 19, 2024, 4:42pm UTC](https://community.influxdata.com/t/bug-in-javascript-client-sdk-and-cloud-error/33620/3 "2024-03-19T16:42:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Zoe\_Steinkamp](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/zoe_steinkamp/32/13300_2.png) [@Zoe\_Steinkamp](https://community.influxdata.com/u/Zoe_Steinkamp)\
**Post date:** [March 19, 2024, 4:43pm UTC](https://community.influxdata.com/t/bug-in-javascript-client-sdk-and-cloud-error/33620/4 "2024-03-19T16:43:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![RickBullotta](https://avatars.discourse-cdn.com/v4/letter/r/779978/32.png) [@RickBullotta](https://community.influxdata.com/u/RickBullotta)\
**Post date:** [March 20, 2024, 11:37am UTC](https://community.influxdata.com/t/bug-in-javascript-client-sdk-and-cloud-error/33620/5 "2024-03-20T11:37:47Z")

</div>

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)
