-
Notifications
You must be signed in to change notification settings - Fork 295
Use safe borrow helpers for NostrDB lookups in networking and cache [untested] #3340
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
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This fixes a crash that would occasionally occur when visiting profiles. NdbTxn objects were being deinitialized on different threads from their initialization, causing incorrect reference count decrements in thread-local transaction dictionaries. This led to premature destruction of shared ndb_txn C objects still in use by other tasks, resulting in use-after-free crashes. The root cause is that Swift does not guarantee tasks resume on the same thread after await suspension points, while NdbTxn's init/deinit rely on thread-local storage to track inherited transaction reference counts. This means that `NdbTxn` objects cannot be used in async functions, as that may cause the garbage collector to deinitialize `NdbTxn` at the end of such function, which may be running on a different thread at that point, causing the issue explained above. The fix in this case is to eliminate the `async` version of the `NdbNoteLender.borrow` method, and update usages to utilize other available methods. Note: This is a rewrite of the fix in damus-io#3329 Note 2: This relates to the fix of an unreleased feature, so therefore no changelog is needed. Changelog-None Co-authored-by: alltheseas <[email protected]> Closes: damus-io#3327 Signed-off-by: Daniel D’Aquino <[email protected]>
Closes: damus-io#3335 Signed-off-by: alltheseas <[email protected]>
Closes: damus-io#3335 Signed-off-by: alltheseas <[email protected]>
11 tasks
Collaborator
Author
|
Changes in this PR do NOT fix #3343 |
Collaborator
Author
|
This PR is too big, and does not seem to fix outstanding crashes. I will instead tackle recent crashes one by one in separate PRs. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
pr-in-queue
The author has multiple active PRs. So this has been placed in a queue behind their other PRs.
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.
Summary
• - 851e855 – Switch networking (findEvent, relay list) and EventCache to the
new borrow helpers to avoid holding raw NdbTxn values.
Ndb.swift, copying to owned values before returning to callers.
Checklist
Experimental Feature Checklist
Tip
This Pull Request is an experimental feature for Damus Labs, and follows a fast-track review process.
The overall requirements are lowered and the review process is not as strict as usual. However, the feature will only be available for Purple users who opt-in.
Changelog-Added: Added experimental feature <X> to Damus LabsStandard PR Checklist
Closes:orFixes:tags in the commit messages wherever applicable, or made sure those are not needed. See Submitting patchesTest report
Please provide a test report for the changes in this PR. You can use the template below, but feel free to modify it as needed.
Device: [Please specify the device you used for testing]
iOS: [Please specify the iOS version you used for testing]
Damus: [Please specify the Damus version or commit hash you used for testing]
Setup: [Please provide a brief description of the setup you used for testing, if applicable]
Steps: [Please provide a list of steps you took to test the changes in this PR]
Results:
Other notes
[Please provide any other information that you think is relevant to this PR.]