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

Many contract function calls/transactions via Web3 will eventually cause TCP ephemeral port exhaustion #926

Closed
hcaw opened this issue Jul 20, 2017 · 4 comments
Assignees
Labels
Enhancement Includes improvements or optimizations

Comments

@hcaw
Copy link

hcaw commented Jul 20, 2017

Description:
Spamming Web3.js with a few thousand transactions or calls in quick succession will eventually (about 30 seconds) cause all available dynamic ports (16384 on Windows) to be consumed - however the vast majority are sitting in TIME_WAIT state (which can be confirmed by running netstat). The onreadystatechange event handler in the sendAsync function in HttpProvider will get called, but request.responseText is empty, causing an exception to be thrown, which is caught but results in an unhelpful error - error: Invalid JSON RPC response: ""

Steps to reproduce:
Execute many successive contract function calls via Web3

Actual Behaviour:
error: Invalid JSON RPC response: "" Error message is being passed into the web3 callback function.

Expected Behaviour:
If all dynamic ports are consumed, then either return a descriptive error message, or hold off until ports are freed by the operating system, or make sure ports are being properly closed after use.

Notes:
To anyone seeing the same issue, it can be temporarily resolved by setting a timeout to wait until the ports are released by the operating system, or by manually increasing available dynamic TCP ports.
For more info - https://blogs.technet.microsoft.com/askds/2008/10/29/port-exhaustion-and-you-or-why-the-netstat-tool-is-your-friend/

Versions:
Geth 1.6.5 - Clique PoA
Web3.js 0.18.4
Windows 10

@hcaw
Copy link
Author

hcaw commented Jul 21, 2017

See similar issue here, albeit on a different project raiden-network/raiden#253

@frozeman
Copy link
Contributor

frozeman commented Aug 8, 2017

The problem is that web3.js is a library running in node OR the browser, so it has no way to see system level port configurations. If you have any idea how we could improve the error messages, feel free to suggest.

@frozeman frozeman added Enhancement Includes improvements or optimizations help wanted labels Aug 8, 2017
@nivida nivida self-assigned this Aug 10, 2018
@csokun
Copy link

csokun commented Jan 5, 2019

HttpProvider makes use of xmlhttprequest which internally disable http.agent https://github.com/driverdan/node-XMLHttpRequest/blob/master/lib/XMLHttpRequest.js#L384

According to nodejs doc https://nodejs.org/docs/latest-v10.x/api/http.html#http_class_http_agent
By providing {agent: false} as an option to the http.get() or http.request() functions, a one-time use Agent with default options will be used for the client connection.

Injecting http.Agent to underline xmlhttprequest probably a way to go:

const httpAgent = new http.Agent({ keepAlive: true, maxSockets: 20  });

@nivida
Copy link
Contributor

nivida commented Jun 20, 2019

I've closed this issue because the last maintenance release of 0.20.x is v0.20.7.

@nivida nivida closed this as completed Jun 20, 2019
mergify bot pushed a commit to celo-org/celo-monorepo that referenced this issue Aug 11, 2020
### Description

- This change should fix the flakey `error: Invalid JSON RPC response: ""` error that we often see in the protocol test beforeEach hooks (particularly those for the Attestations contract). 

- Implements a custom beforeEachWithRetries hook for the protocol tests package that will optionally retry beforeEach hooks and add sleep in between retries. This is necessary to avoid flakiness that seems to be caused by port exhaustion in CI and a mishandling of the error by web3. (See web3/web3.js#3425 and web3/web3.js#926).

- I've only added `beforeEachWithRetries` to the Attestations tests because this error appears there the most. We can add it elsewhere in the future as needed.

### Other changes

None

### Tested

To see that this works, search logs for "retry" in https://circleci.com/gh/celo-org/celo-monorepo/248635

### Related issues

- Fixes #4570

### Backwards compatibility

Not applicable
ewilz pushed a commit to ewilz/celo-monorepo that referenced this issue Sep 29, 2020
### Description

- This change should fix the flakey `error: Invalid JSON RPC response: ""` error that we often see in the protocol test beforeEach hooks (particularly those for the Attestations contract). 

- Implements a custom beforeEachWithRetries hook for the protocol tests package that will optionally retry beforeEach hooks and add sleep in between retries. This is necessary to avoid flakiness that seems to be caused by port exhaustion in CI and a mishandling of the error by web3. (See web3/web3.js#3425 and web3/web3.js#926).

- I've only added `beforeEachWithRetries` to the Attestations tests because this error appears there the most. We can add it elsewhere in the future as needed.

### Other changes

None

### Tested

To see that this works, search logs for "retry" in https://circleci.com/gh/celo-org/celo-monorepo/248635

### Related issues

- Fixes celo-org#4570

### Backwards compatibility

Not applicable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Includes improvements or optimizations
Projects
None yet
Development

No branches or pull requests

4 participants