feat(flushguard): provide interface to close trace manually #10
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR attempt to provide a way manually flush & close subscribers via
close()
in flushguard.This wouldn't be required in normal cases - dropping flushguard, or flush would do the work suffeciently. However there are some edge cases lifecycle of flush is not gracefully controllable in a process lifecycle. The problem I encountered is when subscriber is initialized in node.js's napi context, and if parent process (node.js) forcefully closes via
process.exit()
which doesn't gaurantee to call any cleanup for the native addons. (ref: vercel/next.js#35803 (comment)).To workaround addon passes over references to flushguard to v8's context and pass it back for the manual teardown, then call
close
to complete closes subscriber explicitly. Since napi passes references to the flushguard manual drop wasn't the way to go either.There might be some idomatic way I wasn't aware of and happy to either fix up the PR or close. At least featurewise,
close()
seems to work as expected.