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

[PlayerModel] [Fix] make taskQueueWaitingForInit thread safe #2026

Conversation

jkasten2
Copy link
Member

@jkasten2 jkasten2 commented Mar 9, 2024

Description

One Line Summary

Fix rare null crash with taskQueueWaitingForInit.poll() by making taskQueueWaitingForInit thread safe.

Details

Motivation

A few customers get this rare NPE crash.

Scope

Only affects calls made to OneSignal before the SDK is initialized.

Related Issues

#1761

Crash Example

java.lang.NullPointerException
  at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:116)
  at java.util.concurrent.Executors$DelegatedExecutorService.submit(Executors.java:640)
  at com.onesignal.OSTaskController.startPendingTasks(OSTaskController.java:92)
  at com.onesignal.OSTaskController.$$c(OSTaskController.java:92)
  at com.onesignal.OneSignal.init(OneSignal.java:885)
  at com.onesignal.OneSignal.setAppId(OneSignal.java:737)
  at com.onesignal.OneSignal.reassignDelayedInitParams(OneSignal.java:1180)
  at com.onesignal.OneSignal.onRemoteParamSet(OneSignal.java:889)
  at com.onesignal.OneSignal$7.complete(OneSignal.java:1121)
  at com.onesignal.OneSignalRemoteParams.processJson(OneSignalRemoteParams.java:211)
  at com.onesignal.OneSignalRemoteParams.access$100(OneSignalRemoteParams.java:12)
  at com.onesignal.OneSignalRemoteParams$1.onSuccess(OneSignalRemoteParams.java:156)
  at com.onesignal.OneSignalRestClient$5.run(OneSignalRestClient.java:279)
  at java.lang.Thread.run(Thread.java:922)

Testing

Manual testing

Tested on an Android 14 emulator ensuring a few things work like addTags.

Affected code checklist

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • Public API changes

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
    • If it is hard to explain how any codes changes are related to each other then it most likely needs to be more than one PR
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
  • All automated tests pass, or I explained why that is not possible
    • Tests were already failing on player-model-main
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
    • Simplify with less code, followed by splitting up code into well named functions and variables, followed by adding comments to the code.
  • I have reviewed this PR myself, ensuring it meets each checklist item
    • WIP (Work In Progress) is ok, but explain what is still in progress and what you would like feedback on. Start the PR title with "WIP" to indicate this.

This change is Reviewable

There are two calls to startPendingTasks that can happen on two threads,
which means sometimes taskQueueWaitingForInit.poll() can return null and
throws a NPE when it is given to submit. To handle this we are making
taskQueueWaitingForInit thread safe by calling synchronized on. Doing so
handles this case but also rare cases where something is being added as
we process the queue.
Base automatically changed from fix/player-model-null-timeFocusedAtMs to player-model-main March 9, 2024 01:10
@jkasten2 jkasten2 merged commit a6db7b3 into player-model-main Mar 9, 2024
1 of 2 checks passed
@jkasten2 jkasten2 deleted the fix/player-model-null-taskQueueWaitingForInit.poll branch March 9, 2024 01:10
@jkasten2 jkasten2 mentioned this pull request Mar 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants