-
Notifications
You must be signed in to change notification settings - Fork 87
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
RDART-1020: Fix writeAsync behaviour #1666
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should do that. We're intentionally guiding people toward using the sync API because holding the write lock for extended periods of time is an antipattern and can result in app freezes in multithreaded/process scenarios and can usually be avoided by doing the async calls before entering the write transaction.
My suggestion would be to instead check if T
is a future and log a warning or even error out.
I disagree. We already expose If we force people to not use async callbacks in We should however make such a check in |
Yes, I know it's not difficult to do it and I don't think we should be super actively preventing people from doing it, but I want to make it harder for them to shoot themselves in the foot. The |
a86b769
to
f44e78c
Compare
dd1eef0
to
d73be5f
Compare
try { | ||
T result = writeCallback(); | ||
T result = await writeCallback(); // ignore: await_only_futures |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we await here if we assert the callback isn't a future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😄 ever vigilant. I could just drop it. As is, all that is needed to support async callbacks is to change the return type of writeCallback
from T
to FutureOr<T>
.. and re-enable some skipped tests.
I should probably have put this PR back into in-progress
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.. but it is not a bug per-se .. in dart you can await
non-futures, even null
just fine. It differs from .NET on that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have removed all the new tests again and simply disallowed async callbacks even to writeAsync
.
d73be5f
to
f4dd7f8
Compare
Pull Request Test Coverage Report for Build 9300668832Details
💛 - Coveralls |
* main: RDART-1020: Fix writeAsync behaviour (#1666) RDART-999: Fix flutter test dlopen (#1623) RDART-1045: Expose setrlimit ios (#1700) RDART-962: Use xcode 15.4 (#1548) # Conflicts: # packages/realm_dart/lib/src/cli/install/install_command.dart
* main: Add vNext Changelog header (#1717) [Release 3.0.0] (#1716) libraryVersion moved to realm_libary.dart (take 2) libraryVersion moved to realm_libary.dart Update CHANGELOG (#1715) Github composite action for setting up flutter on runner (#1710) RDART-866: kn/decimal128 web support (#1713) Reduce expected gain of memEquals for test stability Refresh after awaiting download to stabilize tests RDART-866: Minimal web support (#1699) RDART-1052: Update realm-core to v14.9.0 (#1704) RDART-1020: Fix writeAsync behaviour (#1666) RDART-999: Fix flutter test dlopen (#1623) RDART-1045: Expose setrlimit ios (#1700) RDART-962: Use xcode 15.4 (#1548) RDART-1039: Drop catalyst support. Flutter doesn't support it (#1696) # Conflicts: # packages/realm_dart/src/realm-core
This PR has been edited to simply disallow async callbacks in all cases, even to
writeAsync
.Calling
Realm.writeAsync
with an async callback is currently broken, since the callback is not awaited, and not passed as aFutureOr<T> Function()
.The first commit adds tests thats illustrates a number of issues with the current approach, and the second fixes them.
We could consider detecting re-entrancy, and either throw an exception, or simply allow it by participating in the calling transaction, but this is not handled by the current PR.
Fixes: #1667