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

Infinite loop error ws error: connect ECONNREFUSED when sending and confirming raw transactions #28702

Closed
arielsegura opened this issue Nov 1, 2022 · 1 comment
Labels
community Community contribution web3.js Related to the JavaScript client

Comments

@arielsegura
Copy link

arielsegura commented Nov 1, 2022

Problem

SDK Version: 1.66.2

I'm using a solana-test-validator along with test-containers and the problem is that the test-validator shuts down without properly closing the connection (I can't signal the validator to shut down nicely, it also happens while running the test-validator on the terminal without docker). This can happen regardless of the context (in a website or a backend), and the reason is that by default the connection creates the RpcWebSocketClient with options:

{
      autoconnect: false,
      max_reconnects: Infinity,
}

After the test is done and the container is shut down, the output on the console (also in the CI) is:

console.error
    ws error: connect ECONNREFUSED 127.0.0.1:55301

      at Connection.error [as _wsOnError] (node_modules/@solana/web3.js/src/connection.ts:5079:13)
      at Client.emit (../../node_modules/eventemitter3/index.js:181:35)
      at WebSocket.<anonymous> (../../node_modules/rpc-websockets/dist/lib/client.js:458:23)
      at WebSocket.onError (../../node_modules/rpc-websockets/node_modules/ws/lib/event-target.js:220:18)
      at emitErrorAndClose (../../node_modules/rpc-websockets/node_modules/ws/lib/websocket.js:1002:13)
      at ClientRequest.<anonymous> (../../node_modules/rpc-websockets/node_modules/ws/lib/websocket.js:854:5)

on an infinite loop.

Related issues:

#25931
#25578

Proposed Solution

Add a new method in the connection to clean up resources properly and close the websocket nicely, regardless of the server closing the connection abruptely. I come from the Java world, and one would implement Closeable for this type of use cases.

@arielsegura arielsegura added the community Community contribution label Nov 1, 2022
@steveluscher
Copy link
Contributor

I'm rather certain that this is a leak in rpc-websockets (see #25578) and you're right that, unless they are able to plug that leak, the only option for web3.js is to patch around it.

Feel free to reopen this issue if you think it's substantially different than #25578.

@steveluscher steveluscher added the web3.js Related to the JavaScript client label Dec 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community Community contribution web3.js Related to the JavaScript client
Projects
None yet
Development

No branches or pull requests

2 participants