Merge lp:~nikwen/account-polld/fix-qtcontacts-timeout-error into lp:~ubuntu-push-hackers/account-polld/trunk

Proposed by Niklas Wenzel
Status: Merged
Approved by: Jonas G. Drange
Approved revision: 139
Merged at revision: 146
Proposed branch: lp:~nikwen/account-polld/fix-qtcontacts-timeout-error
Merge into: lp:~ubuntu-push-hackers/account-polld/trunk
Prerequisite: lp:~nikwen/account-polld/fix-timeout-handler
Diff against target: 63 lines (+23/-3)
2 files modified
cmd/account-polld/account_manager.go (+2/-0)
cmd/account-polld/main.go (+21/-3)
To merge this branch: bzr merge lp:~nikwen/account-polld/fix-qtcontacts-timeout-error
Reviewer Review Type Date Requested Status
Jonas G. Drange (community) Approve
Review via email: mp+273356@code.launchpad.net

Commit message

Fix a timeout error in the qtcontacts module which occured when a notification was shown directly after creating an account (fixes LP: #1498214)

Description of the change

Fix a timeout error in the qtcontacts module which occured when a notification was shown directly after creating an account (fixes LP: #1498214)

This depends on https://code.launchpad.net/~nikwen/account-polld/fix-timeout-handler/+merge/273351

To post a comment you must log in.
Revision history for this message
Niklas Wenzel (nikwen) wrote :

This does actually need review! It's no WIP anymore.

Revision history for this message
Jonas G. Drange (jonas-drange) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'cmd/account-polld/account_manager.go'
2--- cmd/account-polld/account_manager.go 2015-03-20 17:51:02 +0000
3+++ cmd/account-polld/account_manager.go 2015-10-04 21:40:32 +0000
4@@ -66,6 +66,8 @@
5 close(a.doneChan)
6 }
7
8+// Poll() always needs to be called asynchronously as otherwise qtcontacs' GetAvatar()
9+// will raise an error: "QSocketNotifier: Can only be used with threads started with QThread"
10 func (a *AccountManager) Poll(bootstrap bool) {
11 if !a.authData.Enabled {
12 var ok bool
13
14=== modified file 'cmd/account-polld/main.go'
15--- cmd/account-polld/main.go 2015-10-04 21:40:32 +0000
16+++ cmd/account-polld/main.go 2015-10-04 21:40:32 +0000
17@@ -97,6 +97,8 @@
18 watcher := accounts.NewWatcher(SERVICETYPE_WEBAPPS)
19 mgr := make(map[uint]*AccountManager)
20
21+ var wg sync.WaitGroup
22+
23 L:
24 for {
25 select {
26@@ -106,7 +108,15 @@
27 log.Println("New account data for existing account with id", data.AccountId)
28 account.penaltyCount = 0
29 account.updateAuthData(data)
30- account.Poll(false)
31+ wg.Add(1)
32+ go func() {
33+ defer wg.Done()
34+ // Poll() needs to be called asynchronously as otherwise qtcontacs' GetAvatar() will
35+ // raise an error: "QSocketNotifier: Can only be used with threads started with QThread"
36+ account.Poll(false)
37+ }()
38+ // No wg.Wait() here as it would break GetAvatar() again.
39+ // Instead we have a wg.Wait() before the PollChan polling below.
40 } else {
41 account.Delete()
42 delete(mgr, data.AccountId)
43@@ -131,10 +141,18 @@
44 }
45 mgr[data.AccountId] = NewAccountManager(watcher, postWatch, plugin)
46 mgr[data.AccountId].updateAuthData(data)
47- mgr[data.AccountId].Poll(true)
48+ wg.Add(1)
49+ go func() {
50+ defer wg.Done()
51+ // Poll() needs to be called asynchronously as otherwise qtcontacs' GetAvatar() will
52+ // raise an error: "QSocketNotifier: Can only be used with threads started with QThread"
53+ mgr[data.AccountId].Poll(true)
54+ }()
55+ // No wg.Wait() here as it would break GetAvatar() again.
56+ // Instead we have a wg.Wait() before the PollChan polling below.
57 }
58 case <-pollBus.PollChan:
59- var wg sync.WaitGroup
60+ wg.Wait() // Finish all running Poll() calls before potentially polling the same accounts again
61 for _, v := range mgr {
62 if v.authData.Error != plugins.ErrTokenExpired { // Do not poll if the new token
63 // hasn't been loaded yet

Subscribers

People subscribed via source and target branches