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

@solana/web3.js - requesting a connection.close() method #27464

Closed
mikemaccana opened this issue Aug 30, 2022 · 1 comment
Closed

@solana/web3.js - requesting a connection.close() method #27464

mikemaccana opened this issue Aug 30, 2022 · 1 comment

Comments

@mikemaccana
Copy link
Contributor

Problem

My understanding (from looking at the methods available on the connection object) is there's no way to explicitly close the TCP socket that @solana/web3.js makes to the validator. This doesn't affect anything on production - as the socket is open pretty much all the time - but nearly all test suites will complain with open handles warning unless the socket is explicitly closed.

Integration tests which use @solana/web3.js will complain with something like:

Jest has detected the following 2 open handles potentially keeping Jest from exiting:

  ●  TCPWRAP

      260 |   test(`Get all Bob's token accounts`, async () => {
      261 |     // See https://solana.stackexchange.com/questions/1685/how-do-i-prevent-open-handles-issues-when-using-the-solana-connection-object
    > 262 |     const tokenAccounts = await connection.getTokenAccountsByOwner(
          |                                            ^
      263 |       bob.publicKey,
      264 |       {
      265 |         programId: TOKEN_PROGRAM_ID,

      at node_modules/@solana/web3.js/node_modules/node-fetch/lib/index.js:1468:15
      at Function.fetch [as default] (node_modules/@solana/web3.js/node_modules/node-fetch/lib/index.js:1437:9)
      at fetchImpl (node_modules/@solana/web3.js/src/fetch-impl.ts:12:16)
      at ClientBrowser.fetch [as callServer] (node_modules/@solana/web3.js/src/connection.ts:1173:23)
      at ClientBrowser.Object.<anonymous>.ClientBrowser.request (node_modules/jayson/lib/client/browser/index.js:102:8)
      at request (node_modules/@solana/web3.js/src/connection.ts:1212:14)
      at Connection._rpcRequest (node_modules/@solana/web3.js/src/connection.ts:1211:12)
      at Connection._rpcRequest [as getTokenAccountsByOwner] (node_modules/@solana/web3.js/src/connection.ts:2757:34)
      at Object.<anonymous> (src/tokens.test.ts:262:44)

Proposed Solution

We add a close() method to the Connection object. I'm happy to do this myself if needed (I just want to make sure there's no existing way to close the connection that I have missed first).

@steveluscher
Copy link
Contributor

Thanks! Tracked in #25069.

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

2 participants