Skip to content

Commit

Permalink
changes timeouts to more reasonable values (#206)
Browse files Browse the repository at this point in the history
* changes timeouts to more reasonable values

* use streamClient's timeout values for timeout check
  • Loading branch information
skhugh authored Jun 14, 2024
1 parent 971eb30 commit e2915b8
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions yorkie/src/main/kotlin/dev/yorkie/core/Client.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import kotlin.collections.Map.Entry
import kotlin.coroutines.coroutineContext
import kotlin.time.Duration
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.minutes
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
Expand Down Expand Up @@ -118,6 +119,10 @@ public class Client @VisibleForTesting internal constructor(
private val Document.mutex
get() = mutexForDocuments.getOrPut(key) { Mutex() }

private val streamTimeout = with(streamClient) {
callTimeoutMillis.takeIf { it > 0 } ?: (connectTimeoutMillis + readTimeoutMillis)
}.takeIf { it > 0 }?.milliseconds ?: 5.minutes

public constructor(
host: String,
options: Options = Options(),
Expand Down Expand Up @@ -312,7 +317,7 @@ public class Client @VisibleForTesting internal constructor(
while (true) {
ensureActive()
latestStream.safeClose()
val stream = withTimeoutOrNull(1_000) {
val stream = withTimeoutOrNull(streamTimeout) {
service.watchDocument(
attachment.document.key.documentBasedRequestHeader,
).also {
Expand All @@ -322,7 +327,7 @@ public class Client @VisibleForTesting internal constructor(
val streamJob = launch(start = CoroutineStart.UNDISPATCHED) {
val channel = stream.responseChannel()
while (!stream.isReceiveClosed() && !channel.isClosedForReceive) {
withTimeoutOrNull(60_000) {
withTimeoutOrNull(streamTimeout) {
val receiveResult = channel.receiveCatching()
receiveResult.onSuccess {
attachment.document.publishEvent(StreamConnectionChanged.Connected)
Expand Down

0 comments on commit e2915b8

Please sign in to comment.