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 path_watcher #3920

Merged
merged 4 commits into from
Aug 2, 2023
Merged

Fix path_watcher #3920

merged 4 commits into from
Aug 2, 2023

Conversation

cirospaciari
Copy link
Member

What does this PR do?

  • Documentation or TypeScript types (it's okay to leave the rest blank in this case)
  • Code changes

How did you verify your code works?

Existing tests

@cirospaciari cirospaciari force-pushed the ciro/fix-path_watcher branch from 1335183 to 044a6fa Compare August 1, 2023 16:15
@cirospaciari cirospaciari marked this pull request as ready for review August 1, 2023 16:15
@github-actions
Copy link
Contributor

github-actions bot commented Aug 1, 2023

@cirospaciari 2 files with test failures on linux-x64:

  • test/bundler/bundler_browser.test.ts
  • test/js/node/stubs.test.js

View test output

#4c544cd00b34bb5007e7432176e77708d82da889

@github-actions
Copy link
Contributor

github-actions bot commented Aug 1, 2023

@cirospaciari 2 files with test failures on linux-x64-baseline:

  • test/bundler/bundler_browser.test.ts
  • test/js/node/stubs.test.js

View test output

#4c544cd00b34bb5007e7432176e77708d82da889

@github-actions
Copy link
Contributor

github-actions bot commented Aug 1, 2023

@cirospaciari 3 files with test failures on bun-darwin-aarch64:

  • test/bundler/bundler_browser.test.ts
  • test/js/bun/test/test-test.test.ts
  • test/js/node/stubs.test.js

View test output

#4c544cd00b34bb5007e7432176e77708d82da889

@github-actions
Copy link
Contributor

github-actions bot commented Aug 1, 2023

@cirospaciari 7 files with test failures on bun-darwin-x64-baseline:

  • test/bundler/bundler_browser.test.ts
  • test/js/bun/spawn/spawn-streaming-stdin.test.ts
  • test/js/bun/spawn/spawn-streaming-stdout.test.ts
  • test/js/bun/sqlite/sqlite.test.js
  • test/js/node/stubs.test.js
  • test/js/third_party/webpack/webpack.test.ts
  • test/js/web/timers/setTimeout.test.js

View test output

#4c544cd00b34bb5007e7432176e77708d82da889

Copy link
Collaborator

@Jarred-Sumner Jarred-Sumner left a comment

Choose a reason for hiding this comment

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

This does not fix it? The finalized field is set to true in the same scope as the struct is destroyed, which means all cases the struct is used after finalized is a use after free.

bun.default_allocator.destroy(this);

@cirospaciari
Copy link
Member Author

finalized

It's only used when pending_directories > 0 (on another thread) finalized just say that the owner is gone, when the last task ends/cancel it will call deinit again (but not emit/flush).

@Jarred-Sumner
Copy link
Collaborator

It's not threadsafe though. The finalized boolean would need to be loaded and stored atomically with a @Fence to ensure memory ordering. But even that's not safe because the other thread could be accessing it after deinit

@cirospaciari
Copy link
Member Author

cirospaciari commented Aug 1, 2023

It's not threadsafe though. The finalized boolean would need to be loaded and stored atomically with a @Fence to ensure memory ordering. But even that's not safe because the other thread could be accessing it after deinit

I used mutex to guarantee access to finalized and pending_directories but I found another mistake let me finish it, and you are right about memory ordering

@Jarred-Sumner
Copy link
Collaborator

Not all usages are locked by a mutex. If it were, it would hang until after it’s freed and then segfault

@cirospaciari cirospaciari force-pushed the ciro/fix-path_watcher branch from 044a6fa to f9624bd Compare August 1, 2023 21:07
@cirospaciari cirospaciari force-pushed the ciro/fix-path_watcher branch from 9a8663b to f823987 Compare August 2, 2023 10:53
@Jarred-Sumner Jarred-Sumner merged commit 25553e6 into main Aug 2, 2023
@Jarred-Sumner Jarred-Sumner deleted the ciro/fix-path_watcher branch August 2, 2023 20:00
@Jarred-Sumner
Copy link
Collaborator

Thank you

trnxdev pushed a commit to trnxdev/bun that referenced this pull request Aug 9, 2023
* fix callback and onError

* fix main watcher error return

* fixup

* rename to be more clear
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