Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@smartinio
Copy link
Contributor

Hi,

Noticed that abort behavior wasn't working as expected and found some issues. While fixing them I also noticed everything was pretty old, so I also took some time to update Node.js, Jest, Typescript and get rid of some vulnerabilities. I've split these into separate commits.

The main culprit that lead me to find issues was the use of catch + expect in tests. This is dangerous because if the function does not throw, the test will pass. For the signal tests, I've refactored these to await expect(promise).rejects... but there are more occurrences in other tests.

@smartinio smartinio marked this pull request as ready for review September 24, 2025 03:22
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These should ideally be refactored to await expect(...).rejects but deferring it to a different PR


// handle request options
if (_options.steal === true) {
if (!self._handleExceptionWhenStealIsTrue(_options, reject)) return;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was moved to _handleRequestArgs to consolidate args errors in one place

)
);
return false;
const listener = this._signalOnabort(signal, request);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Opted for returning a listener instead of mutating request inside _signalOnAbort

Comment on lines +42 to +43
// Flush microtask queue
await new Promise((resolve) => setTimeout(resolve, 0));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was needed since lock acquisition now yields execution back to the callers scope for a tick to allow sync abortSignal cancellation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Try-catches were removed from all signal tests because they mask failing tests when the function under test doesn't throw. Ideally this change should be made everywhere, but starting here since abortSignal is the main scope of this PR

Comment on lines -26 to -27
ifAvailable: Boolean;
steal: Boolean;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Drive-by fix. We expect primitive booleans here and not boolean objects.

Comment on lines +46 to +47
closeSignal?: () => void;
signal?: AbortSignal;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added to allow checking signal before lock acquisition as well as remove listener post-acquisition

public async request(...args: RequestArgsCase3) {
const self = this;
return new Promise(async function (resolve, reject) {
return new Promise(function (resolve, reject) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Promise constructor callbacks should not be async

Comment on lines -281 to -299
private _handleExceptionWhenStealIsTrue(
_options: LockOptions,
reject: (reason?: any) => void
) {
if (_options.mode !== LOCK_MODE.EXCLUSIVE) {
reject(
new DOMException(
"Failed to execute 'request' on 'LockManager': The 'steal' option may only be used with 'exclusive' locks."
)
);
return false;
}
if (_options.ifAvailable === true) {
reject(
new DOMException(
"Failed to execute 'request' on 'LockManager': The 'steal' and 'ifAvailable' options cannot be used together."
)
);
return false;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to _handleRequestArgs to consolidate args errors in one place

@aermin
Copy link
Owner

aermin commented Sep 30, 2025

hi @smartinio I in detail Reviewed your MR, your MR is excellent👍🏻 awesome! Approved! Thank you very much!!

@aermin aermin merged commit 723a650 into aermin:main Sep 30, 2025
@aermin
Copy link
Owner

aermin commented Sep 30, 2025

I seems have CI error, could you help fix that? @smartinio ☆⌒(*^-゜)v THX!!

@aermin
Copy link
Owner

aermin commented Sep 30, 2025

image

@smartinio
Copy link
Contributor Author

@aermin Thanks. Oh, okay. Having a look at the error

@smartinio
Copy link
Contributor Author

@aermin I don't have enough repository access to see the details of CI errors, but I do see this annotation: "The job was not started because your account is locked due to a billing issue."

@aermin
Copy link
Owner

aermin commented Oct 1, 2025

hi @smartinio you are right~ I released the new version(0.8.7) for your commits, thanks again!! pls help do the seft-testing in your end side.
thank you for your great contribution🙏🏻

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.

2 participants