Skip to content

Commit 317a99d

Browse files
Fix crash on Android in retry logic after destroy called (#270)
* Fix crash on Android in retry logic after destroy called * PubNub SDK v9.2.4 release. --------- Co-authored-by: PubNub Release Bot <[email protected]>
1 parent 973d1a0 commit 317a99d

File tree

7 files changed

+35
-14
lines changed

7 files changed

+35
-14
lines changed

.pubnub.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name: kotlin
2-
version: 9.2.3
2+
version: 9.2.4
33
schema: 1
44
scm: github.com/pubnub/kotlin
55
files:
6-
- build/libs/pubnub-kotlin-9.2.3-all.jar
6+
- build/libs/pubnub-kotlin-9.2.4-all.jar
77
sdks:
88
-
99
type: library
@@ -23,8 +23,8 @@ sdks:
2323
-
2424
distribution-type: library
2525
distribution-repository: maven
26-
package-name: pubnub-kotlin-9.2.3
27-
location: https://repo.maven.apache.org/maven2/com/pubnub/pubnub-kotlin/9.2.3/pubnub-kotlin-9.2.3.jar
26+
package-name: pubnub-kotlin-9.2.4
27+
location: https://repo.maven.apache.org/maven2/com/pubnub/pubnub-kotlin/9.2.4/pubnub-kotlin-9.2.4.jar
2828
supported-platforms:
2929
supported-operating-systems:
3030
Android:
@@ -114,6 +114,11 @@ sdks:
114114
license-url: https://www.apache.org/licenses/LICENSE-2.0.txt
115115
is-required: Required
116116
changelog:
117+
- date: 2024-08-19
118+
version: v9.2.4
119+
changes:
120+
- type: bug
121+
text: "Fixes a crash on Android after `PubNub.destroy` is called and there are requests running."
117122
- date: 2024-07-29
118123
version: v9.2.3
119124
changes:

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## v9.2.4
2+
August 19 2024
3+
4+
#### Fixed
5+
- Fixes a crash on Android after `PubNub.destroy` is called and there are requests running.
6+
17
## v9.2.3
28
July 29 2024
39

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ You will need the publish and subscribe keys to authenticate your app. Get your
2020
<dependency>
2121
<groupId>com.pubnub</groupId>
2222
<artifactId>pubnub-kotlin</artifactId>
23-
<version>9.2.3</version>
23+
<version>9.2.4</version>
2424
</dependency>
2525
```
2626

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

3232
2. Configure your keys and create PubNub instance:

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ RELEASE_SIGNING_ENABLED=true
1919
SONATYPE_HOST=DEFAULT
2020
SONATYPE_AUTOMATIC_RELEASE=false
2121
GROUP=com.pubnub
22-
VERSION_NAME=9.2.3
22+
VERSION_NAME=9.2.4
2323
POM_PACKAGING=jar
2424

2525
POM_NAME=PubNub SDK

pubnub-core/pubnub-core-impl/src/main/kotlin/com/pubnub/internal/presence/eventengine/effect/WaitEffect.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import com.pubnub.internal.eventengine.Sink
55
import com.pubnub.internal.extension.scheduleWithDelay
66
import com.pubnub.internal.presence.eventengine.event.PresenceEvent
77
import org.slf4j.LoggerFactory
8+
import java.util.concurrent.RejectedExecutionException
89
import java.util.concurrent.ScheduledExecutorService
910
import java.util.concurrent.ScheduledFuture
1011
import kotlin.time.Duration
@@ -29,10 +30,14 @@ internal class WaitEffect(
2930
return
3031
}
3132

32-
scheduled =
33-
executorService.scheduleWithDelay(heartbeatInterval) {
34-
presenceEventSink.add(PresenceEvent.TimesUp)
35-
}
33+
try {
34+
scheduled =
35+
executorService.scheduleWithDelay(heartbeatInterval) {
36+
presenceEventSink.add(PresenceEvent.TimesUp)
37+
}
38+
} catch (_: RejectedExecutionException) {
39+
log.trace("Unable to schedule retry, PubNub was likely already destroyed.")
40+
}
3641
}
3742

3843
@Synchronized

pubnub-core/pubnub-core-impl/src/main/kotlin/com/pubnub/internal/retry/RetryableCallback.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import org.slf4j.LoggerFactory
77
import retrofit2.Call
88
import retrofit2.Callback
99
import retrofit2.Response
10+
import java.util.concurrent.RejectedExecutionException
1011
import java.util.concurrent.ScheduledExecutorService
1112
import kotlin.time.Duration
1213
import kotlin.time.Duration.Companion.milliseconds
@@ -82,8 +83,12 @@ internal abstract class RetryableCallback<T>(
8283
val effectiveDelay: Duration = delay + randomDelayInMillis.milliseconds
8384
log.trace("Added random delay so effective retry delay is ${effectiveDelay.inWholeMilliseconds} millis")
8485
// don't want to block the main thread in case of Android so using executorService
85-
executorService.scheduleWithDelay(effectiveDelay) {
86-
call.clone().enqueue(this)
86+
try {
87+
executorService.scheduleWithDelay(effectiveDelay) {
88+
call.clone().enqueue(this)
89+
}
90+
} catch (_: RejectedExecutionException) {
91+
log.trace("Unable to schedule retry, PubNub was likely already destroyed.")
8792
}
8893
}
8994

pubnub-core/pubnub-core-impl/src/test/kotlin/com/pubnub/api/legacy/PubNubCoreTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class PubNubCoreTest : BaseTest() {
6666
fun getVersionAndTimeStamp() {
6767
val version = PubNubCore.SDK_VERSION
6868
val timeStamp = PubNubCore.timestamp()
69-
assertEquals("9.2.3", version)
69+
assertEquals("9.2.4", version)
7070
assertTrue(timeStamp > 0)
7171
}
7272

0 commit comments

Comments
 (0)