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

changes timeouts to more reasonable values #206

Merged
merged 2 commits into from
Jun 14, 2024
Merged
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
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
Loading