What can an error like this be related to?? It hap...
# coroutines
a
What can an error like this be related to?? It happens when I connect to a ktor server sent event and happens when I send my event exactly the 7th time.
Copy code
java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 1
	at io.ktor.util.pipeline.SuspendFunctionGun$continuation$1.getContext(SuspendFunctionGun.kt:51)
	at io.ktor.util.pipeline.SuspendFunctionGun.getCoroutineContext(SuspendFunctionGun.kt:17)
	at kotlinx.coroutines.CoroutineContextKt.newCoroutineContext(CoroutineContext.kt:19)
	at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:52)
    . . . .
Full stack trace in thread
Copy code
java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 1
	at io.ktor.util.pipeline.SuspendFunctionGun$continuation$1.getContext(SuspendFunctionGun.kt:51)
	at io.ktor.util.pipeline.SuspendFunctionGun.getCoroutineContext(SuspendFunctionGun.kt:17)
	at kotlinx.coroutines.CoroutineContextKt.newCoroutineContext(CoroutineContext.kt:19)
	at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:52)
	at kotlinx.coroutines.BuildersKt.launch(Unknown Source)
	at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(Builders.common.kt:47)
	at kotlinx.coroutines.BuildersKt.launch$default(Unknown Source)
	at sanity.InstallationKt$installSanity$1$1$1.invoke(Installation.kt:30)
	at sanity.InstallationKt$installSanity$1$1$1.invoke(Installation.kt:29)
	at sanity.internal.SubscriberImpl.invoke(SubscriberImpl.kt:11)
	at sanity.internal.AbstractDispatcher.dispatch(AbstractDispatcher.kt:20)
	at raven.BusEmailSender.send(BusEmailSender.kt:14)
	at raven.MailSender.send(MailSender.kt:10)
	at sentinel.RegistrationServiceFlix$sendVerificationLink$1$2$sendTask$1.invokeSuspend(RegistrationServiceFlix.kt:86)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
d
cc @e5l
e
Hey! It looks like a problem in Ktor pipelines, could you tell me if you’re using client or server?
d
It happens when I connect to a ktor server sent event and happens when I send my event exactly the 7th time.
a
this is ktor server
The piece of code that causes the error
Copy code
call.response.cacheControl(CacheControl.NoCache(null))
    call.response.header(HttpHeaders.Connection, "Keep-Alive")
    val ipv4 = call.request.origin.remoteAddress
    println("Connected: $ipv4")
    var subscriber: Subscriber? = null
    call.respondBytesWriter(contentType = ContentType.Text.EventStream) {
        subscriber = bus.subscribe("*") {
            launch {
                writeStringUtf8("id: ${it.topic}\n")
                writeStringUtf8("event: message\n")
                writeStringUtf8("data: ${it.data}\n")
                writeStringUtf8("\n")
                flush()
            }
        }

        while (isActive) { // keep alive for future events
            delay(1000)
        }
    }
    subscriber?.unsubscribe()
    println("Disconnected: $ipv4")
e
It could be an issue with an inner
launch
, @Aleksei Tirman [JB] could you please check?