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

Disable the MaxListenersExceededWarning in Node when creating event targets for internal use #3661

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/odd-jars-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@solana/rpc-subscriptions-channel-websocket': patch
'@solana/transaction-confirmation': patch
'@solana/rpc-subscriptions-spec': patch
'@solana/rpc-subscriptions': patch
'@solana/subscribable': patch
'@solana/rpc': patch
---

Disabled the `MaxListenersExceededWarning` in Node when creating event targets for internal use
1 change: 1 addition & 0 deletions packages/build-scripts/getBaseConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export function getBaseConfig(platform: Platform, formats: Format[], _options: O
// @noble/ed25519 is an ESM-only module, so we have to inline it in CJS builds.
...(format === 'cjs' ? ['@noble/ed25519'] : []),
'@solana/crypto-impl',
'@solana/event-target-impl',
'@solana/text-encoding-impl',
'@solana/ws-impl',
],
Expand Down
1 change: 1 addition & 0 deletions packages/event-target-impl/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/
1 change: 1 addition & 0 deletions packages/event-target-impl/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
engine-strict=true
1 change: 1 addition & 0 deletions packages/event-target-impl/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/
20 changes: 20 additions & 0 deletions packages/event-target-impl/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2023 Solana Labs, Inc

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
57 changes: 57 additions & 0 deletions packages/event-target-impl/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"name": "@solana/event-target-impl",
"version": "0.0.0",
"private": true,
"exports": {
"edge-light": {
"types": "./dist/types/index.browser.d.ts",
"import": "./dist/index.node.mjs",
"require": "./dist/index.node.cjs"
},
"workerd": {
"types": "./dist/types/index.browser.d.ts",
"import": "./dist/index.node.mjs",
"require": "./dist/index.node.cjs"
},
"browser": {
"types": "./dist/types/index.browser.d.ts",
"import": "./dist/index.browser.mjs",
"require": "./dist/index.browser.cjs"
},
"node": {
"types": "./dist/types/index.browser.d.ts",
"import": "./dist/index.node.mjs",
"require": "./dist/index.node.cjs"
}
},
"browser": {
"./dist/index.node.cjs": "./dist/index.browser.cjs",
"./dist/index.node.mjs": "./dist/index.browser.mjs"
},
"main": "./dist/index.node.cjs",
"module": "./dist/index.node.mjs",
"types": "./dist/types/index.browser.d.ts",
"type": "commonjs",
"files": [
"./dist/"
],
"sideEffects": false,
"scripts": {
"compile:js": "tsup",
"compile:typedefs": "tsc -p ./tsconfig.declarations.json",
"dev": "jest -c ../../node_modules/@solana/test-config/jest-dev.config.ts --rootDir . --watch",
"style:fix": "pnpm eslint --fix src && pnpm prettier --log-level warn --ignore-unknown --write ./*",
"test:lint": "TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@solana/test-config/jest-lint.config.ts --rootDir . --silent",
"test:prettier": "TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@solana/test-config/jest-prettier.config.ts --rootDir . --silent",
"test:treeshakability:browser": "agadoo dist/index.browser.mjs",
"test:treeshakability:node": "agadoo dist/index.node.mjs",
"test:typecheck": "tsc --noEmit"
},
"browserslist": [
"supports bigint and not dead",
"maintained node versions"
],
"engines": {
"node": ">=20.18.0"
}
}
2 changes: 2 additions & 0 deletions packages/event-target-impl/src/index.browser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const AbortController = globalThis.AbortController;
export const EventTarget = globalThis.EventTarget;
15 changes: 15 additions & 0 deletions packages/event-target-impl/src/index.node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { setMaxListeners } from 'node:events';

export const AbortController = class extends globalThis.AbortController {
constructor(...args: ConstructorParameters<typeof globalThis.AbortController>) {
super(...args);
setMaxListeners(Number.MAX_SAFE_INTEGER, this.signal);
}
};
Comment on lines +3 to +8
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason behind setting this inside the AbortController constructor as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

signal is an EventTarget, and apparently attaching addEventListener('abort', ...) to it more than 10 times also raises this warning.


export const EventTarget = class extends globalThis.EventTarget {
constructor(...args: ConstructorParameters<typeof globalThis.EventTarget>) {
super(...args);
setMaxListeners(Number.MAX_SAFE_INTEGER, this);
}
};
11 changes: 11 additions & 0 deletions packages/event-target-impl/tsconfig.declarations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"emitDeclarationOnly": true,
"isolatedModules": false,
"outDir": "./dist/types"
},
"extends": "./tsconfig.json",
"include": ["src/index.browser.ts"]
}
9 changes: 9 additions & 0 deletions packages/event-target-impl/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"lib": ["DOM"]
},
"display": "EventTarget Implementation",
"extends": "../tsconfig/base.json",
"include": ["src"]
}
16 changes: 16 additions & 0 deletions packages/event-target-impl/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { defineConfig } from 'tsup';

export default defineConfig(_options =>
(['browser', 'node'] as const).map(platform => ({
entry: [`./src/index.${platform}.ts`],
format: ['cjs', 'esm'],
minify: true,
name: platform,
outExtension({ format }) {
return { js: `.${format === 'cjs' ? 'cjs' : 'mjs'}` };
},
platform,
sourcemap: true,
treeshake: true,
})),
);
5 changes: 5 additions & 0 deletions packages/event-target-impl/typedoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "https://typedoc.org/schema.json",
"extends": ["../typedoc.base.json"],
"entryPoints": ["src/index.ts"]
}
1 change: 1 addition & 0 deletions packages/rpc-subscriptions-channel-websocket/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
],
"dependencies": {
"@solana/errors": "workspace:*",
"@solana/event-target-impl": "workspace:*",
"@solana/functional": "workspace:*",
"@solana/rpc-subscriptions-spec": "workspace:*",
"@solana/subscribable": "workspace:*"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
SOLANA_ERROR__RPC_SUBSCRIPTIONS__CHANNEL_FAILED_TO_CONNECT,
SolanaError,
} from '@solana/errors';
import { EventTarget } from '@solana/event-target-impl';
import { RpcSubscriptionsChannel } from '@solana/rpc-subscriptions-spec';
import { getDataPublisherFromEventEmitter } from '@solana/subscribable';
import WebSocket from '@solana/ws-impl';
Expand Down
1 change: 1 addition & 0 deletions packages/rpc-subscriptions-spec/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
],
"dependencies": {
"@solana/errors": "workspace:*",
"@solana/event-target-impl": "workspace:*",
"@solana/promises": "workspace:*",
"@solana/rpc-spec-types": "workspace:*",
"@solana/subscribable": "workspace:*"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
SOLANA_ERROR__RPC_SUBSCRIPTIONS__EXPECTED_SERVER_SUBSCRIPTION_ID,
SolanaError,
} from '@solana/errors';
import { AbortController } from '@solana/event-target-impl';
import { safeRace } from '@solana/promises';
import { createRpcMessage, RpcRequest, RpcResponseData, RpcResponseTransformer } from '@solana/rpc-spec-types';
import { DataPublisher } from '@solana/subscribable';
Expand Down
1 change: 1 addition & 0 deletions packages/rpc-subscriptions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
],
"dependencies": {
"@solana/errors": "workspace:*",
"@solana/event-target-impl": "workspace:*",
"@solana/fast-stable-stringify": "workspace:*",
"@solana/functional": "workspace:*",
"@solana/promises": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { isSolanaError, SOLANA_ERROR__RPC_SUBSCRIPTIONS__CHANNEL_CONNECTION_CLOSED } from '@solana/errors';
import { AbortController } from '@solana/event-target-impl';
import type { RpcSubscriptionsChannel } from '@solana/rpc-subscriptions-spec';

type Config<TChannel extends RpcSubscriptionsChannel<unknown, unknown>> = Readonly<{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AbortController } from '@solana/event-target-impl';
import { RpcSubscriptionsChannelCreator } from '@solana/rpc-subscriptions-spec';

import { ChannelPoolEntry, createChannelPool } from './rpc-subscriptions-channel-pool-internal';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AbortController } from '@solana/event-target-impl';
import fastStableStringify from '@solana/fast-stable-stringify';
import { RpcSubscriptionsTransport } from '@solana/rpc-subscriptions-spec';
import { DataPublisher } from '@solana/subscribable';
Expand Down
1 change: 1 addition & 0 deletions packages/rpc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
],
"dependencies": {
"@solana/errors": "workspace:*",
"@solana/event-target-impl": "workspace:*",
"@solana/fast-stable-stringify": "workspace:*",
"@solana/functional": "workspace:*",
"@solana/rpc-api": "workspace:*",
Expand Down
1 change: 1 addition & 0 deletions packages/rpc/src/rpc-request-coalescer.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AbortController } from '@solana/event-target-impl';
import type { RpcTransport } from '@solana/rpc-spec';
import type { RpcResponse } from '@solana/rpc-spec-types';

Expand Down
3 changes: 2 additions & 1 deletion packages/subscribable/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
"maintained node versions"
],
"dependencies": {
"@solana/errors": "workspace:*"
"@solana/errors": "workspace:*",
"@solana/event-target-impl": "workspace:*"
},
"peerDependencies": {
"typescript": ">=5"
Expand Down
2 changes: 2 additions & 0 deletions packages/subscribable/src/__tests__/data-publisher-test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { EventTarget } from '@solana/event-target-impl';

import { DataPublisher, getDataPublisherFromEventEmitter } from '../data-publisher';

describe('a data publisher', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/subscribable/src/async-iterable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
SOLANA_ERROR__INVARIANT_VIOLATION__SUBSCRIPTION_ITERATOR_STATE_MISSING,
SolanaError,
} from '@solana/errors';
import { AbortController } from '@solana/event-target-impl';

import { DataPublisher } from './data-publisher';

Expand Down
2 changes: 2 additions & 0 deletions packages/subscribable/src/demultiplex.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { EventTarget } from '@solana/event-target-impl';

import { DataPublisher, getDataPublisherFromEventEmitter } from './data-publisher';

export function demultiplexDataPublisher<
Expand Down
1 change: 1 addition & 0 deletions packages/transaction-confirmation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"@solana/addresses": "workspace:*",
"@solana/codecs-strings": "workspace:*",
"@solana/errors": "workspace:*",
"@solana/event-target-impl": "workspace:*",
"@solana/keys": "workspace:*",
"@solana/promises": "workspace:*",
"@solana/rpc": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED, SolanaError } from '@solana/errors';
import { AbortController } from '@solana/event-target-impl';
import type { GetEpochInfoApi, Rpc } from '@solana/rpc';
import type { RpcSubscriptions, SlotNotificationsApi } from '@solana/rpc-subscriptions';
import type { Commitment } from '@solana/rpc-types';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Address } from '@solana/addresses';
import { getBase58Decoder, getBase64Encoder } from '@solana/codecs-strings';
import { SOLANA_ERROR__INVALID_NONCE, SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND, SolanaError } from '@solana/errors';
import { AbortController } from '@solana/event-target-impl';
import { safeRace } from '@solana/promises';
import type { GetAccountInfoApi, Rpc } from '@solana/rpc';
import type { AccountNotificationsApi, RpcSubscriptions } from '@solana/rpc-subscriptions';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AbortController } from '@solana/event-target-impl';
import type { Signature } from '@solana/keys';
import { safeRace } from '@solana/promises';
import type { Commitment } from '@solana/rpc-types';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getSolanaErrorFromTransactionError } from '@solana/errors';
import { AbortController } from '@solana/event-target-impl';
import type { Signature } from '@solana/keys';
import { safeRace } from '@solana/promises';
import type { GetSignatureStatusesApi, Rpc } from '@solana/rpc';
Expand Down
20 changes: 20 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"exclude": [
"packages/build-scripts",
"packages/crypto-impl",
"packages/event-target-impl",
"packages/fetch-impl",
"packages/rpc-graphql",
"packages/test-config",
Expand Down
Loading