Skip to content

WebSocketProvider.destroy() trigger an error #4678

@VladimirDiamandi

Description

@VladimirDiamandi

Ethers Version

6.11.1

Search Terms

No response

Describe the Problem

If there are active subscriptions, the error will be thrown after some time after calling the provider.destroy() method.
As I understand the cause of the error is this line, because this.#destoyed is set to true before the asynchronous function "this.removeAllListeners()" is executed, as a consequence, an exception is thrown in the send method.

Code Snippet

No response

Contract ABI

No response

Errors

Error: provider destroyed; cancelled request (operation="eth_unsubscribe", code=UNSUPPORTED_OPERATION, version=6.11.1)
    at makeError (/node_modules/ethers/lib.commonjs/utils/errors.js:129:21)
    at WebSocketProvider.send (/node_modules/ethers/lib.commonjs/providers/provider-jsonrpc.js:742:60)
    at /node_modules/ethers/lib.commonjs/providers/provider-socket.js:51:28 {
  code: 'UNSUPPORTED_OPERATION',
  operation: 'eth_unsubscribe',
  shortMessage: 'provider destroyed; cancelled request'
}

Environment

No response

Environment (Other)

No response

Metadata

Metadata

Assignees

Labels

bugVerified to be an issue.fixed/completeThis Bug is fixed or Enhancement is complete and published.v6Issues regarding v6

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions