Skip to content

Commit ace1910

Browse files
authored
fix(data) Events timeout fix (#3058)
1 parent f300d1e commit ace1910

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

appsync/aws-sdk-appsync-events/src/main/java/com/amazonaws/sdk/appsync/events/utils/ConnectionTimeoutTimer.kt

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,27 @@ internal class ConnectionTimeoutTimer(
2727

2828
private var timeoutInMillis: Long = 300_000L
2929
private var timeoutJob: Job? = null
30+
private val lock = Object()
3031

3132
fun resetTimeoutTimer(timeoutInMillis: Long = this.timeoutInMillis) {
32-
if (this.timeoutInMillis != timeoutInMillis) {
33-
this.timeoutInMillis = timeoutInMillis
34-
}
33+
synchronized(lock) {
34+
if (this.timeoutInMillis != timeoutInMillis) {
35+
this.timeoutInMillis = timeoutInMillis
36+
}
3537

36-
timeoutJob?.cancel() // Cancel existing timer if any
37-
timeoutJob = scope.launch {
38-
delay(timeoutInMillis)
39-
// If this code executes, it means no events were received for the duration of timeoutInMillis
40-
onTimeout()
38+
timeoutJob?.cancel() // Cancel existing timer if any
39+
timeoutJob = scope.launch {
40+
delay(timeoutInMillis)
41+
// If this code executes, it means no events were received for the duration of timeoutInMillis
42+
onTimeout()
43+
}
4144
}
4245
}
4346

4447
fun stop() {
45-
timeoutJob?.cancel()
46-
timeoutJob = null
48+
synchronized(lock) {
49+
timeoutJob?.cancel()
50+
timeoutJob = null
51+
}
4752
}
4853
}

0 commit comments

Comments
 (0)