mirror of
https://github.com/ushahidi/SMSSync.git
synced 2026-04-25 15:55:57 +03:00
[GH-ISSUE #411] SyncPendingMessagesService uniqueness check appears unreliable #291
Labels
No labels
Bug report
Code improvement
Concern
Feature request
Feature request
Good first issue to work on
In progress
Needs info
Question
Ready
Translation
User Experience
User Experience
Website
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/SMSSync#291
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @alxndrsn on GitHub (Apr 7, 2016).
Original GitHub issue: https://github.com/ushahidi/SMSSync/issues/411
Apparent issues
From reading the code of
SyncPendingMessagesService, it appears theisServiceWorking()method is meant to ensure that only a single instance of the class is ever executing at one time.mServiceassignment not safemServiceis set without checking if has been set previously:github.com/ushahidi/SMSSync@a1f2224bbb/smssync/src/main/java/org/addhen/smssync/presentation/service/SyncPendingMessagesService.java (L89)This appears to mean that if multiple service instance were created, only the most recent will be assigned to
SyncPendingMessagesService.mService. Even though one or many older instances could still be running, this will not be reported bySyncPendingMessagesService.isServiceWorking().mServiceproperty not thread-safeShared property
mServiceis accessed in a non thread-safe way:github.com/ushahidi/SMSSync@a1f2224bbb/smssync/src/main/java/org/addhen/smssync/presentation/service/SyncPendingMessagesService.java (L83)github.com/ushahidi/SMSSync@a1f2224bbb/smssync/src/main/java/org/addhen/smssync/presentation/service/SyncPendingMessagesService.java (L89)github.com/ushahidi/SMSSync@a1f2224bbb/smssync/src/main/java/org/addhen/smssync/presentation/service/SyncPendingMessagesService.java (L192)In rare cases this could lead to a
NullPointerExceptioninisWorking().isWorking()will only evaluatetrueat an unspecified time in the futureisWorking()returnstrueif the service'sgetState().state == SyncStatus.SYNC. However, this value is only assigned inSyncPendingMessagesTask.syncPending(), which is only called fromSyncPendingMessagesTask.sync(), which is only called from ``SyncPendingMessagesTask.doInBackground()](https://github.com/ushahidi/SMSSync/blob/a1f2224bbb4488a9772eb35a1d8648e0dc350a59/smssync/src/main/java/org/addhen/smssync/presentation/task/SyncPendingMessagesTask.java#L92), which is run, via [thisTaskAsync.execute()` call, on a different thread.Possible effects
It seems likely that pending messages can be sent multiple times if multiple instances of
SyncPendingMessagesServiceare run in parallel.@alxndrsn commented on GitHub (Apr 8, 2016):
As
SyncPendingMessagesServiceis a subclass ofIntentService, thread-safety may not be an issue.