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

add and remove are not async safe #2685

Open
uriva opened this issue Oct 17, 2023 · 6 comments
Open

add and remove are not async safe #2685

uriva opened this issue Oct 17, 2023 · 6 comments
Labels

Comments

@uriva
Copy link

uriva commented Oct 17, 2023

What version of this package are you using?
^2.1.27

What operating system, Node.js, and npm version?

ubuntu 23.4
v19.0.0
8.19.2

What happened?
It's possible to get add and remove to throw if calling them in parallel, even with different hash ids.

What did you expect to happen?

remove should not throw if it can't find the torrent.

add should not throw if the torrent is already added.

Are you willing to submit a pull request to fix this bug?
yes

@ThaUnknown
Copy link
Member

those are async functions, you simply need to run

await client.add()

and

await client.remove()

@uriva
Copy link
Author

uriva commented Oct 17, 2023

consider the case where add is called from different places in the code. If there is an sync context switch inside add, then we can be inside it twice.

await is not equivalent to a lock.

@ThaUnknown
Copy link
Member

fair

@ThaUnknown ThaUnknown reopened this Oct 17, 2023
@uriva
Copy link
Author

uriva commented Oct 17, 2023

while we're at it, these functions should probably not have a cb parameter and be async at the same time.

@uriva uriva changed the title add and remove are not async safe under heavy load add and remove are not async safe Oct 17, 2023
@ThaUnknown
Copy link
Member

ThaUnknown commented Oct 17, 2023

they should be, but not as a part of this issue

this was planned for ages: https://github.com/orgs/webtorrent/projects/1#card-60702582

they became async because other issues were being blocked by it, and using .then would be useless if it was later re-written to await anyways, and dropping callback based calls for webtorrent, means doing it inside close to 20 packages, which requries a lot of testing and rewriting

Copy link

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

@github-actions github-actions bot added the stale label Dec 17, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 25, 2023
@ThaUnknown ThaUnknown reopened this Dec 25, 2023
@ThaUnknown ThaUnknown added accepted and removed stale labels Dec 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants