Skip to content

Commit c5ab899

Browse files
authored
fix(hive): disable autoDispose (ardatan#7069)
* fix(hive): disable `autoDispose` * Add tests
1 parent 19e90eb commit c5ab899

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

.changeset/late-ghosts-turn.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@graphql-mesh/plugin-hive': patch
3+
---
4+
5+
Do not hook into `terminate` events of Node.js, because Mesh handles it already
6+
7+
Hooking into those events cause a memory leak because plugins are initialized on each polling iteration in legacy Mesh CLI/Runtime

packages/plugins/hive/src/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ export default function useMeshHive(
105105
usage,
106106
reporting,
107107
selfHosting,
108-
autoDispose: ['SIGINT', 'SIGTERM'],
108+
// Mesh already disposes the client below on Mesh's `destroy` event
109+
autoDispose: false,
109110
});
110111
function onTerminate() {
111112
return hiveClient
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { PubSub } from '@graphql-mesh/utils';
2+
import useMeshHive from '../src';
3+
4+
describe('Hive', () => {
5+
let pubsub: PubSub;
6+
beforeEach(() => {
7+
pubsub = new PubSub();
8+
});
9+
afterEach(() => {
10+
pubsub.publish('destroy', undefined);
11+
});
12+
it('does not hook into Node.js process', () => {
13+
const spy = jest.spyOn(process, 'once');
14+
useMeshHive({
15+
enabled: true,
16+
pubsub,
17+
token: 'FAKE_TOKEN',
18+
}).onPluginInit?.({
19+
addPlugin: jest.fn(),
20+
plugins: [],
21+
setSchema: jest.fn(),
22+
registerContextErrorHandler: jest.fn(),
23+
});
24+
expect(spy).not.toHaveBeenCalled();
25+
});
26+
});

0 commit comments

Comments
 (0)