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: handle outdated message in channel queue #184

Merged
merged 11 commits into from
Oct 7, 2024

Conversation

jedlikowski
Copy link
Contributor

@jedlikowski jedlikowski commented Sep 4, 2024

Fixes #183

Copy link

changeset-bot bot commented Sep 4, 2024

🦋 Changeset detected

Latest commit: 44881df

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
synckit Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

codesandbox-ci bot commented Sep 4, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@JounQin
Copy link
Member

JounQin commented Sep 6, 2024

What's the issue here? Can you provide more information? Reproduction or failing test for example.

@jedlikowski jedlikowski marked this pull request as draft September 9, 2024 05:17
@jedlikowski
Copy link
Contributor Author

jedlikowski commented Sep 9, 2024

Hi, sorry, it was meant to be a draft PR ;) I've linked in the description to the issue this PR means to fix.

@jedlikowski
Copy link
Contributor Author

jedlikowski commented Sep 9, 2024

Hi, I've added one more change to avoid sending the worker task result to parent if parent isn't waiting for the result anymore. Let me know what you think of this PR and I'll be happy to carry it to the end :)

I also wondered how we could pass some sort of EventEmitter to the task function itself, to let it know that the task has been aborted. This would allow it for example to cancel a HTTP request, but I couldn't figure out a way to do it without changing the library API.

This chart aims visualize the current behavior (dotted line means Atomics.wait() timeout on parent process):
image

While this one shows the updated behavior:
image

@jedlikowski
Copy link
Contributor Author

Hi, @JounQin, what do you think of this PR? Would you be interested in such a contribution?

@jedlikowski jedlikowski marked this pull request as ready for review September 17, 2024 10:14
@KubaZ
Copy link

KubaZ commented Sep 24, 2024

Hi @JounQin, could you please take a look at this PR?

@JounQin
Copy link
Member

JounQin commented Sep 24, 2024

Interesting, is that possible to add a related test case?

@jedlikowski
Copy link
Contributor Author

Interesting, is that possible to add a related test case?

Hi @JounQin , I've added a test case that will currently fail on main branch and pass on this branch: https://github.com/un-ts/synckit/pull/184/files#diff-708937a178903f6cba26c362f7fda7d1da8fb676b66c79dbd63fbffdc7a2db96R107-R125

image

@JounQin JounQin force-pushed the fix-timeout-subsequent-messages branch from b66f1a5 to e1dd83b Compare September 30, 2024 16:18
Copy link

codecov bot commented Sep 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (35a89ea) to head (44881df).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #184   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         1           
  Lines          204       218   +14     
  Branches       101       105    +4     
=========================================
+ Hits           204       218   +14     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@JounQin
Copy link
Member

JounQin commented Oct 1, 2024

Could all lines except if (expectedId !== id) be test covered?

@jedlikowski
Copy link
Contributor Author

Could all lines except if (expectedId !== id) be test covered?

I've been trying to achieve that. AFAIK these are the only other lines not covered:

if (id < expectedId) {
  const waitingTime = Date.now() - start
  return receiveMessageWithId(
    port,
    expectedId,
    waitingTimeout ? waitingTimeout - waitingTime : undefined,
  )
}

Adding coverage for them in a stable manner would require us to mock receiveMessageOnPort so that it returns expectedId - 1 on first call and expectedId on second call. This is currently not possible in jest in ESM environment, because partial module mocking is not supported. Due to lack of support, it would be required to mock the whole node:worker_threads module 😞

@jedlikowski
Copy link
Contributor Author

jedlikowski commented Oct 2, 2024

Good news @JounQin, I've managed add tests for those lines 😄 Could you take a look?

@jedlikowski
Copy link
Contributor Author

Hi @JounQin, could you also add hacktoberfest label to this PR? 😄

@JounQin JounQin merged commit 30d28ae into un-ts:main Oct 7, 2024
18 checks passed
@JounQin
Copy link
Member

JounQin commented Oct 7, 2024

Thanks for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

syncFn timeout causes subsequent calls to fail.
3 participants