Skip to content

Commit 1d64ef8

Browse files
Copilothotlong
andcommitted
Fix error listener memory leak in JSON-RPC server startup
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 872ca1a commit 1d64ef8

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

packages/protocols/json-rpc/src/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,14 @@ export class JSONRPCPlugin implements RuntimePlugin {
199199

200200
// Start listening
201201
await new Promise<void>((resolve, reject) => {
202-
this.server!.on('error', reject);
202+
const onError = (err: Error) => {
203+
this.server!.removeListener('error', onError);
204+
reject(err);
205+
};
206+
207+
this.server!.on('error', onError);
203208
this.server!.listen(this.config.port, () => {
209+
this.server!.removeListener('error', onError);
204210
console.log(`[${this.name}] 🚀 JSON-RPC server listening on http://localhost:${this.config.port}${this.config.basePath}`);
205211
resolve();
206212
});

0 commit comments

Comments
 (0)