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

Fix crash on Android in retry logic after destroy called #270

Merged
merged 2 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: kotlin
version: 9.2.3
version: 9.2.4
schema: 1
scm: github.com/pubnub/kotlin
files:
- build/libs/pubnub-kotlin-9.2.3-all.jar
- build/libs/pubnub-kotlin-9.2.4-all.jar
sdks:
-
type: library
Expand All @@ -23,8 +23,8 @@ sdks:
-
distribution-type: library
distribution-repository: maven
package-name: pubnub-kotlin-9.2.3
location: https://repo.maven.apache.org/maven2/com/pubnub/pubnub-kotlin/9.2.3/pubnub-kotlin-9.2.3.jar
package-name: pubnub-kotlin-9.2.4
location: https://repo.maven.apache.org/maven2/com/pubnub/pubnub-kotlin/9.2.4/pubnub-kotlin-9.2.4.jar
supported-platforms:
supported-operating-systems:
Android:
Expand Down Expand Up @@ -114,6 +114,11 @@ sdks:
license-url: https://www.apache.org/licenses/LICENSE-2.0.txt
is-required: Required
changelog:
- date: 2024-08-19
version: v9.2.4
changes:
- type: bug
text: "Fixes a crash on Android after `PubNub.destroy` is called and there are requests running."
- date: 2024-07-29
version: v9.2.3
changes:
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v9.2.4
August 19 2024

#### Fixed
- Fixes a crash on Android after `PubNub.destroy` is called and there are requests running.

## v9.2.3
July 29 2024

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ You will need the publish and subscribe keys to authenticate your app. Get your
<dependency>
<groupId>com.pubnub</groupId>
<artifactId>pubnub-kotlin</artifactId>
<version>9.2.3</version>
<version>9.2.4</version>
</dependency>
```

* for Gradle, add the following dependency in your `gradle.build`:
```groovy
implementation 'com.pubnub:pubnub-kotlin:9.2.3'
implementation 'com.pubnub:pubnub-kotlin:9.2.4'
```

2. Configure your keys and create PubNub instance:
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ RELEASE_SIGNING_ENABLED=true
SONATYPE_HOST=DEFAULT
SONATYPE_AUTOMATIC_RELEASE=false
GROUP=com.pubnub
VERSION_NAME=9.2.3
VERSION_NAME=9.2.4
POM_PACKAGING=jar

POM_NAME=PubNub SDK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.pubnub.internal.eventengine.Sink
import com.pubnub.internal.extension.scheduleWithDelay
import com.pubnub.internal.presence.eventengine.event.PresenceEvent
import org.slf4j.LoggerFactory
import java.util.concurrent.RejectedExecutionException
import java.util.concurrent.ScheduledExecutorService
import java.util.concurrent.ScheduledFuture
import kotlin.time.Duration
Expand All @@ -29,10 +30,14 @@ internal class WaitEffect(
return
}

scheduled =
executorService.scheduleWithDelay(heartbeatInterval) {
presenceEventSink.add(PresenceEvent.TimesUp)
}
try {
scheduled =
executorService.scheduleWithDelay(heartbeatInterval) {
presenceEventSink.add(PresenceEvent.TimesUp)
}
} catch (_: RejectedExecutionException) {
log.trace("Unable to schedule retry, PubNub was likely already destroyed.")
}
}

@Synchronized
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.slf4j.LoggerFactory
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
import java.util.concurrent.RejectedExecutionException
import java.util.concurrent.ScheduledExecutorService
import kotlin.time.Duration
import kotlin.time.Duration.Companion.milliseconds
Expand Down Expand Up @@ -82,8 +83,12 @@ internal abstract class RetryableCallback<T>(
val effectiveDelay: Duration = delay + randomDelayInMillis.milliseconds
log.trace("Added random delay so effective retry delay is ${effectiveDelay.inWholeMilliseconds} millis")
// don't want to block the main thread in case of Android so using executorService
executorService.scheduleWithDelay(effectiveDelay) {
call.clone().enqueue(this)
try {
executorService.scheduleWithDelay(effectiveDelay) {
call.clone().enqueue(this)
}
} catch (_: RejectedExecutionException) {
log.trace("Unable to schedule retry, PubNub was likely already destroyed.")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class PubNubCoreTest : BaseTest() {
fun getVersionAndTimeStamp() {
val version = PubNubCore.SDK_VERSION
val timeStamp = PubNubCore.timestamp()
assertEquals("9.2.3", version)
assertEquals("9.2.4", version)
assertTrue(timeStamp > 0)
}

Expand Down
Loading