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

fix: recycleWorkers to destroy idle workers when runtime changes #75

Merged
merged 1 commit into from Nov 5, 2023

Conversation

AriPerkkio
Copy link
Member

@AriPerkkio AriPerkkio commented Nov 5, 2023

Idle workers are not recycled when runtime changes and isolateWorkers: true option is used.

tinypool/src/index.ts

Lines 1074 to 1081 in 999778e

if (options?.runtime) {
this.options.runtime = options.runtime
}
// Worker's are automatically recycled when isolateWorkers is enabled
if (this.options.isolateWorkers) {
return
}

This bug was introduced in https://github.com/tinylibs/tinypool/pull/65/files#diff-a2a171449d862fe29692ce031981047d7ab755ae7f84c707aef80701b3ea0c80R1073 where runtime changing during recycleWorkers was introduced.

@@ -169,6 +169,26 @@ test('runtime can be changed after recycle', async () => {
})
})

test('isolated idle workers change runtime after recycle', async () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

This test fails with following error when fix is reverted:

  ● isolated idle workers change runtime after recycle

expect(received).resolves.toMatchObject(expected)

- Expected  - 2
+ Received  + 8

  Array [
    Object {
-     "isChildProcess": true,
+     "isTinypoolWorker": true,
+     "isWorkerThread": true,
+     "workerData": undefined,
+     "workerId": 2,
    },
    Object {
-     "isChildProcess": true,
+     "isTinypoolWorker": true,
+     "isWorkerThread": true,
+     "workerData": undefined,
+     "workerId": 1,
    },
  ]

@Aslemammad Aslemammad merged commit e79c650 into tinylibs:main Nov 5, 2023
6 checks passed
@AriPerkkio AriPerkkio deleted the fix/recycle-isolated-workers branch November 5, 2023 13:33
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

Successfully merging this pull request may close these issues.

None yet

2 participants