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

try to fix notifications #1969

Closed
wants to merge 8 commits into from
Closed

Conversation

Simon-Laux
Copy link
Member

@Simon-Laux Simon-Laux commented Nov 14, 2023

Does not crash as often anymore, but:

  • delay after waking up / unsuspeding, link2xt said probably because of missing cache, also might just be sqlcipher taking long to open the db
  • events are not received by the UI anymore, althrough I sucessfully restarted the handler that the events are printed to the console.
  • there is a performance warning because I wait in the main thread for the event thread to finish: "Thread Performance Checker: Thread running at QOS_CLASS_USER_INTERACTIVE waiting on a lower QoS thread running at QOS_CLASS_BACKGROUND. Investigate ways to avoid priority inversions"
  • TODO: eventHandlerActive boolean should proabably be an atomic? -> seems to be not necessary
  • it wastes time when going in the background, sometimes just waits while doing nothing, Dedicated Background Fetch function deltachat-core-rust#4420 could be useful here. - though keeping open a bit for the case that user comes back to the app is a feature, not a bug

Also See

closes #1979
closes #1830
closes #1202 (basically the same as #1979)

if crashes still continue, we should open new, on-point issues

@r10s
Copy link
Member

r10s commented Nov 14, 2023

great to push this forward and to have a fresh look at the current state. thanks a lot!

i know, this is a draft, but still:

for easier review, merging and more on point discussions, please do not put unrelated and many things into one pull requests. small pull requests, fixing a precisely formulated issues are easier to review are much more probable to get in soon (eg. the logging could be one pr)

also, please do not shift blocks around, this also makes it very hard to find the gist of the change. this whole area is very sensible and complicated already, and one does not always is in the correct mindset, so keep it simple

@Simon-Laux
Copy link
Member Author

Simon-Laux commented Nov 14, 2023

yeah would have made more sense to split the changes over multiple commits.
creating a dedicated pr for moving the logger away from context is a good idea, by the way it it still needed that it is pluggable/changable? or could we just import the simple logger everywhere?

Edit: made an issue for the logging discussion: #1973

Edit2: made two prs about reducing context dependence in the event loop: #1978, #1976 (after those are merged I can rebase this pr to make it simpler, but the biggest impact in simplification would be a pr that deals with #1973)

@Simon-Laux Simon-Laux force-pushed the simon/try-fix-notifications branch from 4c76c58 to 5db309f Compare November 15, 2023 00:47
@Simon-Laux Simon-Laux force-pushed the simon/try-fix-notifications branch from 5db309f to a10e2a5 Compare November 16, 2023 17:30
@Simon-Laux Simon-Laux force-pushed the simon/try-fix-notifications branch 2 times, most recently from 796da09 to 237bfed Compare November 16, 2023 23:02
@Simon-Laux
Copy link
Member Author

seems like this fixed the resume issue

it did not, just got it again (now event handler is false though)

@Simon-Laux
Copy link
Member Author

since last commit resume works reliable for me.

@r10s
Copy link
Member

r10s commented Nov 23, 2023

i simplified the logging part at #1994 - once #1994 is merged, this pr should be rebased and become much simpler

@r10s r10s added the bug label Nov 23, 2023
@Simon-Laux Simon-Laux force-pushed the simon/try-fix-notifications branch 2 times, most recently from e5cb84f to 4695142 Compare November 24, 2023 15:45
Does not crash as often anymore, but:
- [ ] delay after waking up / unsuspeding, link2xt said probably because of missing cache
- [ ] events are not received by the UI anymore, althrough I sucessfully restarted the handler that the events are printed to the console.
- [ ] there is a performance warning because I wait in the main thread for the event thread to finish: "Thread Performance Checker: Thread running at QOS_CLASS_USER_INTERACTIVE waiting on a lower QoS thread running at QOS_CLASS_BACKGROUND. Investigate ways to avoid priority inversions"

add more logging and add a startio statement

but this didn't fix the issue of the broken state on resume

add reloadDcContext, seems like this fixed the resume issue

do not close db if app is in foreground after fetch
@r10s r10s force-pushed the simon/try-fix-notifications branch from dec5c9f to 5d72c11 Compare December 1, 2023 16:44
r10s added 5 commits December 1, 2023 22:25
- add 'private' where possible
- remove superfluous 'self'
- remove trailing semicolon
- embrace existing startup / shutdown logging style
- log encrypted accounts on point (errors are anways logged always)
@r10s r10s marked this pull request as ready for review December 2, 2023 18:46
@r10s
Copy link
Member

r10s commented Dec 4, 2023

this PR in its current form leads to issues when the app is restarted after being suspended to memory before (so if applicationWillTerminate() is not called and we land in maybeStart() on restart):

in this case, the whole app stays in memory - while all context objects get invalidated by closeDB() EDIT: after chat with @link2xt, they're not invalidated, but still there are other contexts objects after result.

later in maybeStart(), the accounts object is recreated, with new context objects. leading to weird behaviours or crashes as parts of the app use the old context objects while other parts use the new

the account suspend/resume idea from before would have avoided that situation.

otoh, suspend/resume would introduce another state in core, which will have issues on its own, so i tend to follow the approach starting in this PR of calling dc_accounts_unref() on suspend.

so, this PR is necessary, but not sufficient: additionally, we need to invalidate all context objects returned by dc_accounts_get*() - maybe that is not that-hard as the swift wrapper objects can stay as is, we could eg. use a function to get the account object that fulfils the conditions

@r10s
Copy link
Member

r10s commented Dec 6, 2023

after some chatting with core devs deep into things, this PR does basically two things:

  1. graceful shutdown event handler, fix crashes with previous shutdown of event handlers

  2. avoid 0xdead10cc crashes that happens as the account's lock file is kept open to avoid only one account instance to add accounts. these 0xdead10cc crashes are avoided by calling dc_accounts_unref() - which has side effects and other issues as described above

other than i have thought initially, this PR does not change anything on dc_context_t and possible 0xdead10cc crashes related to them: accounts that you get with dc_accounts_get_*() should stay valid even after dc_accounts_unref() they are not closed or so; you can still use them and have to dc_context_unref() them in the end

todo:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants