Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting an ECONNRESET error while trying to run the examples #284

Closed
Imod7 opened this issue Feb 23, 2023 · 1 comment
Closed

Getting an ECONNRESET error while trying to run the examples #284

Imod7 opened this issue Feb 23, 2023 · 1 comment

Comments

@Imod7
Copy link
Collaborator

Imod7 commented Feb 23, 2023

I get an ECONNRESET error message when trying to run any of the examples in txwrapper-core.
More specifically while having a local node running, I go in packages/txwrapper-examples folder and I run :

yarn run polkadot
or
yarn run multisig

and I get the error

FetchError: request to http://0.0.0.0:9933/ failed, reason: read ECONNRESET
    at ClientRequest.<anonymous> (/Volumes/T7/Parity/txwrapper-core/node_modules/node-fetch/lib/index.js:1491:11)
    at ClientRequest.emit (node:events:512:28)
    at Socket.socketErrorListener (node:_http_client:496:9)
    at Socket.emit (node:events:512:28)
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  type: 'system',
  errno: 'ECONNRESET',
  code: 'ECONNRESET'
}

I did quite some research to check if it is related to nodejs or node-fetch or http but I could not find something that solved my problem.
I run with NODE_DEBUG=net so I can get more details on what is happening. So I run NODE_DEBUG=net yarn run polkadot and the result was

NET 14398: createConnection [
  [Object: null prototype] {
    protocol: 'http:',
    slashes: true,
    auth: null,
    host: '0.0.0.0',
    port: '9933',
    hostname: '0.0.0.0',
    hash: null,
    search: null,
    query: null,
    pathname: '/',
    path: null,
    href: 'http://0.0.0.0:9933/',
    method: 'POST',
    headers: [Object: null prototype] {
      'Content-Type': [Array],
      Accept: [Array],
      'Content-Length': [Array],
      'User-Agent': [Array],
      'Accept-Encoding': [Array],
      Connection: [Array]
    },
    agent: undefined,
    keepAlive: true,
    scheduling: 'lifo',
    timeout: 5000,
    noDelay: true,
    servername: '',
    _agentKey: '0.0.0.0:9933:',
    encoding: null,
    keepAliveInitialDelay: 1000
  },
  [Function (anonymous)],
  [Symbol(normalizedArgs)]: true
]
NET 14398: pipe false null
NET 14398: _read
NET 14398: _read wait for connection
NET 14398: afterConnect
NET 14398: _read
NET 14398: Socket._handle.readStart
NET 14398: _read
NET 14398: destroy
NET 14398: close
NET 14398: close handle
FetchError: request to http://0.0.0.0:9933/ failed, reason: read ECONNRESET
    at ClientRequest.<anonymous> (/Volumes/T7/Parity/txwrapper-core/node_modules/node-fetch/lib/index.js:1491:11)
    at ClientRequest.emit (node:events:512:28)
    at Socket.socketErrorListener (node:_http_client:496:9)
    at Socket.emit (node:events:512:28)
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  type: 'system',
  errno: 'ECONNRESET',
  code: 'ECONNRESET'
}

While trying to debug and fix my issue I run into different posts the mention that ECONNRESET errors are related to :

  • socket hang up errors
  • when a socket was closed but did not receive any response
  • keepAliveTimeout setting

Based on some of the resources I found :

I started looking on how to keep the connection open when doing the request through fetch and I found this example

Solution

So as soon as I added the line

'connection': 'keep-alive',

in the headers in the util.ts I did not get any ECONNRESET errors and all the examples worked smoothly.

@Imod7 Imod7 changed the title Adding connection keep-alive solved ECONNRESET error Getting ECONNRESET errors while trying to run the examples Feb 23, 2023
@Imod7 Imod7 changed the title Getting ECONNRESET errors while trying to run the examples Getting an ECONNRESET error while trying to run the examples Feb 23, 2023
@Imod7
Copy link
Collaborator Author

Imod7 commented Feb 23, 2023

Closing this issue since the change was pushed with this commit.

@Imod7 Imod7 closed this as completed Feb 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant