-
Notifications
You must be signed in to change notification settings - Fork 888
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 Rewards reset failing on Windows #6274
Conversation
|
||
// Close any open files before deleting them below (required on | ||
// Windows) | ||
file_task_runner_->DeleteSoon(FROM_HERE, rewards_database_.release()); |
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.
Closing the database wasn't a great option, as it led to some cascading problems in other parts of the code that weren't expecting or testing for a closed database. Releasing the database seems safer and we handle it properly elsewhere (and it's already being done later in the reset process).
My understanding of DeleteSoon
is that it fires the release immediately after unwinding the current function stack and will therefore always run before the task we post to delete the files. Let me know if that doesn't sound like a good approach though.
|
||
// Close any open files before deleting them below (required on | ||
// Windows) | ||
file_task_runner_->DeleteSoon(FROM_HERE, rewards_database_.release()); |
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.
Looks like OnCompleteReset
calls StopLedger
which does this delete of the rewards database. Does CompleteReset
need to call StopLedger
before deleting all of the files? Like that would be the last thing that it does instead of the first?
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'm not opposed to something like that, but StopLedger
is also asynchronous. I'm a little leery about changing this too deeply, as there could be some unintended side effects (just ran into one with the staging server on Android yesterday in fact).
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.
In the ideal world, it seems like the OnCompleteReset
callback should do nothing but call observers and run its success callback. CompleteReset
should shutdown ledger and then (when that completes) close and delete files. That approach is definitely a little more complicated than the current solution, but also feels a bit more "correct". What do you think @NejcZdovc?
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.
@emerick sure, adjust PR and let's see how it will work
3a53f29
to
707c40f
Compare
} | ||
|
||
void RewardsServiceImpl::OnStopLedger(const ledger::Result result) { | ||
void RewardsServiceImpl::OnStopLedgerInternal( |
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.
In order to minimize confusion between OnStopLedgerInternal
and OnStopLedger
we might want to name things a bit differently. Maybe the new one should be something along the lines of:
OnStopLedgerForCompleteReset
OnCompleteResetStopLedger
OnCompleteResetLedgerStopped
etc.
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.
Great suggestion, I went with the first one - thanks!
0cd68a6
to
b8af1e7
Compare
@@ -1458,7 +1458,7 @@ void RewardsServiceImpl::SetRewardsMainEnabled(bool enabled) { | |||
|
|||
if (!enabled) { | |||
RecordRewardsDisabledForSomeMetrics(); | |||
StopLedger(); | |||
StopLedger(base::BindOnce([](ledger::Result) {})); |
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.
you can just do StopLedger(base::DoNothing())
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.
Really helpful! Fixed.
b8af1e7
to
0635cfe
Compare
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.
Just tried it on macOS and it crashes
[1650:775:0731/212314.492165:FATAL:thread_restrictions.cc(78)] Check failed: !g_blocking_disallowed.Get().Get(). Function marked as blocking was called from a scope that disallows blocking! If this task is running inside the ThreadPool, it needs to have MayBlock() in its TaskTraits. Otherwise, consider making this blocking work asynchronous or, as a last resort, you may use ScopedAllowBlocking (see its documentation for best practices).
g_blocking_disallowed currently set to true by
0 libbase.dylib 0x00000001042dd119 base::debug::CollectStackTrace(void**, unsigned long) + 9
1 libbase.dylib 0x00000001041a3e33 base::debug::StackTrace::StackTrace() + 19
2 libbase.dylib 0x0000000104295c12 base::DisallowUnresponsiveTasks() + 50
3 libcontent.dylib 0x0000000111407b52 content::BrowserMainLoop::PreMainMessageLoopRun() + 98
4 libcontent.dylib 0x0000000111aea307 content::StartupTaskRunner::RunAllTasksNow() + 119
5 libcontent.dylib 0x0000000111406a28 content::BrowserMainLoop::CreateStartupTasks() + 744
6 libcontent.dylib 0x0000000111409b14 content::BrowserMainRunnerImpl::Initialize(content::MainFunctionParams const&) + 100
7 libcontent.dylib 0x0000000111404d1b content::BrowserMain(content::MainFunctionParams const&) + 251
8 libcontent.dylib 0x000000011206379c content::ContentMainRunnerImpl::RunServiceManager(content::MainFunctionParams&, bool) + 1036
9 libcontent.dylib 0x0000000112063363 content::ContentMainRunnerImpl::Run(bool) + 467
10 libembedder.dylib 0x0000000104149389 service_manager::Main(service_manager::MainParams const&) + 3321
11 libcontent.dylib 0x0000000112062668 content::ContentMain(content::ContentMainParams const&) + 120
12 libchrome_dll.dylib 0x00000001050f4d75 ChromeMain + 277
13 Brave Browser Development 0x0000000103a0d69f main + 287
14 libdyld.dylib 0x00007fff68508cc9 start + 1
0 libbase.dylib 0x00000001042dd119 base::debug::CollectStackTrace(void**, unsigned long) + 9
1 libbase.dylib 0x00000001041a3e33 base::debug::StackTrace::StackTrace() + 19
2 libbase.dylib 0x00000001041c5185 logging::LogMessage::~LogMessage() + 261
3 libbase.dylib 0x00000001041c5e8e logging::LogMessage::~LogMessage() + 14
4 libbase.dylib 0x0000000104294cd5 base::internal::AssertBlockingAllowed() + 149
5 libbase.dylib 0x000000010428b459 base::ScopedBlockingCall::ScopedBlockingCall(base::Location const&, base::BlockingType) + 121
6 libbase.dylib 0x00000001042e1108 base::File::Close() + 152
7 libchrome_dll.dylib 0x0000000105aa7fe7 brave_rewards::RewardsServiceImpl::OnStopLedgerForCompleteReset(base::OnceCallback<void (bool)>, ledger::mojom::Result) + 279
8 libchrome_dll.dylib 0x0000000105ac47db void base::internal::InvokeHelper<true, void>::MakeItSo<void (brave_rewards::RewardsServiceImpl::*)(base::OnceCallback<void (bool)>, ledger::mojom::Result), base::WeakPtr<brave_rewards::RewardsServiceImpl>, base::OnceCallback<void (bool)>, ledger::mojom::Result>(void (brave_rewards::RewardsServiceImpl::*&&)(base::OnceCallback<void (bool)>, ledger::mojom::Result), base::WeakPtr<brave_rewards::RewardsServiceImpl>&&, base::OnceCallback<void (bool)>&&, ledger::mojom::Result&&) + 203
9 libchrome_dll.dylib 0x0000000105ac4703 base::internal::Invoker<base::internal::BindState<void (brave_rewards::RewardsServiceImpl::*)(base::OnceCallback<void (bool)>, ledger::mojom::Result), base::WeakPtr<brave_rewards::RewardsServiceImpl>, base::OnceCallback<void (bool)> >, void (ledger::mojom::Result)>::RunOnce(base::internal::BindStateBase*, ledger::mojom::Result) + 35
10 libchrome_dll.dylib 0x0000000105aa7eb2 brave_rewards::RewardsServiceImpl::OnStopLedger(base::OnceCallback<void (ledger::mojom::Result)>, ledger::mojom::Result) + 994
11 libchrome_dll.dylib 0x0000000105ac11fb void base::internal::InvokeHelper<true, void>::MakeItSo<void (brave_rewards::RewardsServiceImpl::*)(base::OnceCallback<void (ledger::mojom::Result)>, ledger::mojom::Result), base::WeakPtr<brave_rewards::RewardsServiceImpl>, base::OnceCallback<void (ledger::mojom::Result)>, ledger::mojom::Result>(void (brave_rewards::RewardsServiceImpl::*&&)(base::OnceCallback<void (ledger::mojom::Result)>, ledger::mojom::Result), base::WeakPtr<brave_rewards::RewardsServiceImpl>&&, base::OnceCallback<void (ledger::mojom::Result)>&&, ledger::mojom::Result&&) + 203
12 libchrome_dll.dylib 0x0000000105ac1123 base::internal::Invoker<base::internal::BindState<void (brave_rewards::RewardsServiceImpl::*)(base::OnceCallback<void (ledger::mojom::Result)>, ledger::mojom::Result), base::WeakPtr<brave_rewards::RewardsServiceImpl>, base::OnceCallback<void (ledger::mojom::Result)> >, void (ledger::mojom::Result)>::RunOnce(base::internal::BindStateBase*, ledger::mojom::Result) + 35
13 libchrome_dll.dylib 0x0000000105b15d21 bat_ledger::mojom::BatLedger_Shutdown_ForwardToCallback::Accept(mojo::Message*) + 257
14 libbindings.dylib 0x0000000104819656 mojo::InterfaceEndpointClient::HandleValidatedMessage(mojo::Message*) + 1462
15 libbindings.dylib 0x000000010481d71b mojo::MessageDispatcher::Accept(mojo::Message*) + 251
16 libbindings.dylib 0x000000010481a9b1 mojo::InterfaceEndpointClient::HandleIncomingMessage(mojo::Message*) + 97
17 libbindings.dylib 0x0000000104823848 mojo::internal::MultiplexRouter::ProcessIncomingMessage(mojo::internal::MultiplexRouter::MessageWrapper*, mojo::internal::MultiplexRouter::ClientCallBehavior, base::SequencedTaskRunner*) + 1400
18 libbindings.dylib 0x0000000104822d10 mojo::internal::MultiplexRouter::Accept(mojo::Message*) + 400
19 libbindings.dylib 0x000000010481d71b mojo::MessageDispatcher::Accept(mojo::Message*) + 251
20 libbindings.dylib 0x0000000104811dd4 mojo::Connector::DispatchMessage(mojo::Message) + 452
21 libbindings.dylib 0x00000001048128b7 mojo::Connector::ReadAllAvailableMessages() + 279
0635cfe
to
8e3ce4e
Compare
Fixed crash, I had been testing in release mode which doesn't crash on blocking calls. Great catch @NejcZdovc. |
8e3ce4e
to
eb52c3a
Compare
Verification passed on
|
Resolves brave/brave-browser#10934
Submitter Checklist:
npm run lint
)git rebase master
(if needed).git rebase -i
to squash commits (if needed).Test Plan:
Reviewer Checklist:
After-merge Checklist:
changes has landed on.