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 queue management in jest-worker #7934

Merged
merged 1 commit into from Feb 19, 2019
Merged

Fix queue management in jest-worker #7934

merged 1 commit into from Feb 19, 2019

Conversation

mjesun
Copy link
Contributor

@mjesun mjesun commented Feb 19, 2019

Nodes in a linked list were shared among all lists for each worker; which is not what we would like to do. The expected part to be shared is only the request object (which uses the first position as a lock between jobs); but the wrapper object for the linked list needs to be unique.

I also added a test that would crash without the fix.


return this;
}

private _enqueue(task: QueueChildMessage, workerId: number): Farm {
const item = {task, next: null};
Copy link
Contributor Author

@mjesun mjesun Feb 19, 2019

Choose a reason for hiding this comment

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

The core of the fix is only this line; where instead of pushing to all queues the task object, we create one specifically for each queue, (meaning that when doing .next in the tail of a linked list, we don't affect all others).

The rest of the PR are "cosmetic" changes, and the test.

this._offset++;

return this;
}

lock(workerId: number): void {
private _lock(workerId: number): void {
Copy link
Member

Choose a reason for hiding this comment

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

technically breaking, but I guess these shouldn't be called anyways by consumers?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, playing with worker locks is a recipe for disaster :D

@@ -14,7 +14,8 @@
- `[jest-changed-files]` Improve default file selection for Mercurial repos ([#7880](https://github.com/facebook/jest/pull/7880))
- `[jest-validate]` Fix validating async functions ([#7894](https://github.com/facebook/jest/issues/7894))
- `[jest-circus]` Fix bug with test.only ([#7888](https://github.com/facebook/jest/pull/7888))
- `[jest-transform]` Normalize config and remove unecessary checks, convert `TestUtils.js` to TypeScript ([#7801](https://github.com/facebook/jest/pull/7801)
- `[jest-transform]` Normalize config and remove unecessary checks, convert `TestUtils.js` to TypeScript ([#7801](https://github.com/facebook/jest/pull/7801))
Copy link
Member

Choose a reason for hiding this comment

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

took me forever to spot the fixed missing paren :P

@mjesun mjesun merged commit 7cc0771 into jestjs:master Feb 19, 2019
private _locks: Array<boolean>;
private _numOfWorkers: number;
private _offset: number;
private _queue: Array<QueueChildMessage | null>;
private _queue: Array<QueueItem | null>;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
private _queue: Array<QueueItem | null>;
private _queue: Array<QueueItem>;

right? there can never be nulls in the queue now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The queue can be empty, and that's signaled by a null item.

Copy link
Member

Choose a reason for hiding this comment

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

so Array<QueueItem> | [null]? I guess it doesn't matter in practice

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The array index refers to each of the workers (I.e. this._queue.length is numOfWorkers, not the list of jobs); so each item in the array is either the first element of the linked list, or null.

@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants