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

Leak investigation 2 #173

Merged
merged 10 commits into from
Mar 28, 2023
Merged

Leak investigation 2 #173

merged 10 commits into from
Mar 28, 2023

Conversation

danfuzz
Copy link
Owner

@danfuzz danfuzz commented Mar 27, 2023

This PR focuses on fixing the memory leaks that remained after addressing the ones fixed by introducing Promise.race(), which were surprisingly non-zero in number.

  1. The original "safe Promise.race()" implementation itself had a variation of the original leak, though it's super-understandable why it wasn't caught earlier. Specifically, the original version was tested by allocating bunches of objects which didn't have any references between them, so it was easy not to notice that there was (literally) one more than you'd expect when running the test to see if the new version leaked. In the case of this project, a single leak of the "wrong" race contender acts kind of like a trip-wire which then causes massive excess memory consumption (due to the nature of the links from each LinkedEvent to its next-event).
  2. During investigation of the former, I ran across a bug in V8 which caused a leak but only when you attach a debugger. But due to the nature of what was being leaked in this case (another case of a LinkedEvent which would then hold onto every subsequently-emitted event for the life of the process), it seemed worthwhile to work around the problem, which turned out not to be too awful to do. I left a big ole comment in the code explaining what's going on.

danfuzz added 10 commits March 27, 2023 16:25
...which only shows up when you attach a debugger.
* Fix a memory leak in the inherited implementation.
* Write a new implementation:
  * Written in my usual "obviously correct" style. (Bug notwithstanding, the
    inherited version was basically correct, but it read to me more as "not
    obviously wrong" than "obviously correct.")
  * Uses `async` / `await` syntax where possible (which I generally prefer).

I'm going to leave the old implementation in for at least one PR before
removing it, for source history continuity.
@danfuzz danfuzz merged commit a1f573b into main Mar 28, 2023
@danfuzz danfuzz deleted the leak-investigation-2 branch March 28, 2023 00:21
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.

1 participant