Operating System: Amazon Linux (deployed in ECS fargate). Dockerfile is using strapi/base
Database: mysql
Node Version: >=10.16.0 <=14.x.x
NPM Version: ^6.0.0
Yarn Version:
We are using strapi for our service but we keep encountering errors that are not replicable but often occur during low traffic. Any tips are appreciated. Thank you
It seems the connection from BE AWS ALB → Strapi (BE) is terminated forcibly without the ALB acknowledging that BE already closed the connection causing 502 errors.
Below is the sample error from our logs for ECONNRESET error.
Message: [2022-04-12T02:56:04.741] [ERROR] default - FetchError: request to https://URL_HERE failed, reason: read ECONNRESET
at ClientRequest.<anonymous> (/PATH_TO_FILE/index.js:1461:11)
at ClientRequest.emit (events.js:400:28)
at TLSSocket.socketErrorListener (_http_client.js:475:9)
at TLSSocket.emit (events.js:400:28)
at emitErrorNT (internal/streams/destroy.js:106:8)
at emitErrorCloseNT (internal/streams/destroy.js:74:3)
at processTicksAndRejections (internal/process/task_queues.js:82:21) {
type: 'system',
errno: 'ECONNRESET',
code: 'ECONNRESET'
Solutions that were implemented but did not fixed the issue
The same strapi’s keepAliveTimeout and headersTimeout value
502 are gateway failures, typically in a proxy layer where the proxy can’t talk to the upstream service. You say that you have apache with mod_proxy for your frontend but I see no proxy layer except ALB there, is that the only proxy layer?
A front end application will process request and for someEndpoint requests it will be processed by the Nuxtjs application. This is configured with apache as shown below.
and the Nuxtjs application will then communicate to our strapi backend through ALB which is described in the below flow
Nuxt.js (FE) → BE AWS ALB → Strapi (BE)
However, our strapi service sometimes responds the ECONNRESET error. This is happening on requests that are only communicated with strapi service and during low traffic.
ECONNRESET is generally a network layer issue where the connection was closed/reset. It could be happening between the ALB or between Strapi and it’s database but I would need more information to know for sure.
I’m trying to resolve what appears to be the same. Getting intermittent 502 failed to fetch in my Sentry error logs only 1 or 2 a day. Tried different configurations for Ram and CPU since ECS is hosting the strapi v3 app.
How did you configure strapi keep alive timeout? Can’t find any info on where to toggle that.
To troubeshoot the problem, you can firstly put nuxt infront of ELB and temporary remove apache.
You should be able to tune up Nuxtjs with a larger KeepAliveTimeout and headersTimeout with a hook nuxtjs config that larger than that of ELB.
In Strapi, also doing the same things in it’s bootstrap.
You can try to set it in /src/index.js, You can bootstrap it, with the following code.
I think turning on keepAlive is necessary. Hope this help, for any detail setting, feel free to leave me message.
Sorry, I’m no longer associated with my previous company where I encountered this issue, and wasn’t able to check on this for the longest time due to difference of domain/tech stack in my current work.
IIRIC we did adjust the keepAliveTimeout, headersTimeout , and keepAlive settings of strapi but it did not totally fixed the issue. We tried different combination of timeout configurations but we still couldn’t fix and/or understand the issue. It did lessen(not significantly) the occurrence of the error but the issue still occur.