undici icon indicating copy to clipboard operation
undici copied to clipboard

`request` error `read ECONNRESET`

Open dowmeister opened this issue 1 year ago • 6 comments

Bug Description

Probably this is not even a bug but is driving me crazy and i'm asking for help (or an hug)

Context is an Electron app based on Electron 22 and Node v16, sometimes POST or PATCH requests fail with read ECONNRESET error at TLSWrap.onStreamRead (node:internal/stream_base_commons:217:20)

Other requets work fine, this happens for some users, mostly - for what i've seen - connected to internet with a wireless connection that probably is not really stable, but the app works totally fine and is offline tolerant, the game they are playing on has a multiplayer module that needs to be connected to internet and don't lose the connection.

Axios or undici there is no difference, for same users, fails in the same way.

Among other things, the app sends a POST request in a certain moment - and it works - after a while, for other reasons, sends other POSTS requests and these fails for ECONNRESET.

I'm asking for help to understand how debug this, find a reliable reason or eventually fix it.

I've never reproduced this situation, considering the app has thousands concurrent users, this happens to a relatively small users portion, but still, it happens.

Posted data is pretty simple:

{"job_id":14039010,"event_type":"tollgate_paid","x":-5502.788726806641,"y":65.37895965576172,"z":28128.698669433594,"attributes":{"amount":6}}

Is something with keepAlive? TLS protocols? IP resolution? mixed IPV6/IPV4 network?

Thaks for your help and sorry if is not related.

Reproducible By

Expected Behavior

Logs & Screenshots

Environment

Electron 22 Node 16 Windows 11 or 10

Additional context

dowmeister avatar Oct 19 '24 15:10 dowmeister

Not much we can do without some sort of reproduction. ECONNRESET issues can happen for a variety of reasons. Since you mentioned it happens regardless of the client, I suspect it is something in your application code.

connected to internet with a wireless connection that probably is not really stable

Are you able to reproduce by doing something like canceling a request while it is mid-execution?

Ethan-Arrowood avatar Oct 19 '24 21:10 Ethan-Arrowood

thanks for getting back to me.

i would be happy is something in my application code, at least would mean is fixable :D

can it be caused by the fact that functions are exported directly and not encapsulated in an class instance? maybe is something with resuing a closed connection?

 const result = await TruckyHubApiService.completeJobPost(
            remote_job_id as number,
            data
          );
export default {
...
  cancelJobPost,
...
};
async function completeJobPost(
  job_id: number,
  job: Job
): Promise<CompleteJobResponse> {
  return executeRequest(
    `/v1/job/${job_id}/complete`,
    'POST',
    job,
    true
  ) as Promise<CompleteJobResponse>;
}

do you have any suggestion to simulate the request cancelling in mid-execution?

Thanks again

dowmeister avatar Oct 20 '24 08:10 dowmeister

We will be able to help you better if you can isolate the problem as much as you can by providing an Minimum Reproducible Example

metcoder95 avatar Oct 20 '24 08:10 metcoder95

can it be caused by the fact that functions are exported directly and not encapsulated in an class instance?

No, most likely this is not the issue.

maybe is something with resuing a closed connection?

Yes, if a connection is closed, and it is being reused directly then it would result in an ECONNRESET error. Undici guards against this. Are you doing some unique with the API?

Ethan-Arrowood avatar Oct 21 '24 04:10 Ethan-Arrowood

No, all stateless requests authenticated with authorization header, nothing fancy

dowmeister avatar Oct 21 '24 06:10 dowmeister

i met the same problem that you have got, you can try to upgrade your node version to 18 and above,you may solve this problem this way,but it dont know why it works

cyh2020 avatar Jul 22 '25 11:07 cyh2020