Issues and errors on production website

Hi all,
we’ve recently published a Vue Storefront 1.x website.

Sometimes, it seems random because as now we don’t know the origin, the API doesn’t respond.

Those are some logs that we’ve collected:

2020-09-25 13:27:17: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
    at ServerResponse.setHeader (_http_outgoing.js:518:11)
    at ServerResponse.header (/var/www/petrone/app/vue-storefront-api/node_modules/express/lib/response.js:771:10)
    at ServerResponse.contentType (/var/www/petrone/app/vue-storefront-api/node_modules/express/lib/response.js:599:15)
    at Object.<anonymous> (/var/www/petrone/app/vue-storefront-api/dist/api/img.js:38:10)
    at (<anonymous>)
    at fulfilled (/var/www/petrone/app/vue-storefront-api/node_modules/tslib/tslib.js:107:62)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
2020-09-25 03:30:24: (node:12869) UnhandledPromiseRejectionWarning: RangeError [ERR_HTTP_INVALID_STATUS_CODE]: Invalid status code: EBUSY
    at ServerResponse.writeHead (_http_server.js:248:11)
    at ServerResponse.writeHead (/var/www/petrone/app/vue-storefront-api/node_modules/on-headers/index.js:44:26)
    at ServerResponse._implicitHeader (_http_server.js:239:8)
    at write_ (_http_outgoing.js:642:9)
    at ServerResponse.end (_http_outgoing.js:753:5)
    at ServerResponse.send (/var/www/petrone/app/vue-storefront-api/node_modules/express/lib/response.js:221:10)
    at ServerResponse.json (/var/www/petrone/app/vue-storefront-api/node_modules/express/lib/response.js:267:15)
    at apiStatus (/var/www/petrone/app/vue-storefront-api/dist/lib/util.js:80:22)
    at Object.apiError (/var/www/petrone/app/vue-storefront-api/dist/lib/util.js:92:12)
    at /var/www/petrone/app/vue-storefront-api/dist/api/catalog.js:84:24

2020-09-25 03:30:24: (node:12869) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see (rejection id: 2)
(node:12869) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

┌──  api Logs  ──────────────────────────────────────────────────────────────────────────────────────────────┐
│[ 0] api     Mem: 668 MB    CPU:  0 %  onlin ││ api >     at ServerResponse.writeHead (_http_server.js:248:11)                                             │
│[ 1] o2m     Mem:  38 MB    CPU:  0 %  onlin ││ api >     at ServerResponse.writeHead (/var/www/petrone/app/vue-storefront-api/node_modules/on-headers/in  │
│[34] server     Mem: 218 MB    CPU:  5 %  on ││ api >     at ServerResponse._implicitHeader (_http_server.js:239:8)                                        │
│[35] server     Mem: 229 MB    CPU: 11 %  on ││ api >     at write_ (_http_outgoing.js:642:9)                                                              │
│[36] server     Mem: 207 MB    CPU:  5 %  on ││ api >     at ServerResponse.end (_http_outgoing.js:753:5)                                                  │
│[37] server     Mem: 282 MB    CPU:  5 %  on ││ api >     at ServerResponse.send (/var/www/petrone/app/vue-storefront-api/node_modules/express/lib/respon  │
│[38] server     Mem: 196 MB    CPU:  8 %  on ││ api >     at ServerResponse.json (/var/www/petrone/app/vue-storefront-api/node_modules/express/lib/respon  │
│[39] server     Mem: 202 MB    CPU:  4 %  on ││ api >     at apiStatus (/var/www/petrone/app/vue-storefront-api/dist/lib/util.js:80:22)                    │
│[40] server     Mem: 219 MB    CPU: 29 %  on ││ api >     at Object.apiError (/var/www/petrone/app/vue-storefront-api/dist/lib/util.js:92:12)              │
│[41] server     Mem: 207 MB    CPU:  5 %  on ││ api >     at /var/www/petrone/app/vue-storefront-api/dist/api/catalog.js:84:24                             │
│[42] server     Mem: 211 MB    CPU: 11 %  on ││ api > 2020-09-25 13:06:40: (node:6482) UnhandledPromiseRejectionWarning: Unhandled promise rejection

Any ideas about how can we solve this problem?

It looks like some of your endpoint sends response (e.g. with apiStatus/apiError) - but the function does not return and still goes forward. Then probably it tries to send response again! That’s source of the first error.

The last error says that you written some async code (async/await or just promise) and did not catch the error with (try…catch or .catch(…)).

You should fix these 2 and restart API.

Thanks a lot for your clear response @Fifciuu

And about this error, what could be the problem?

@rozzilla It was fixed here


Thanks a lot for this response!