Illegal trailing byte
- Dominant language
- Kotlin
- Stars
- 14.5k
- Forks
- 1.3k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 49
Description
### Ktor Version
1.1.3
### Ktor Engine Used(client or server and name)
jetty server
### JVM Version, Operating System and Relevant Context
11, Windows 10
### Feedback
I get the following error on a big/long session:
```
kotlinx.io.charsets.MalformedInputException: Illegal trailing byte
at kotlinx.coroutines.io.ByteBufferChannel$readUTF8LineToUtf8Suspend$2.invokeSuspend(ByteBufferChannel.kt:2130)
at kotlinx.coroutines.io.ByteBufferChannel$readUTF8LineToUtf8Suspend$2.invoke(ByteBufferChannel.kt)
at kotlinx.coroutines.io.ByteBufferChannel.lookAheadSuspend(ByteBufferChannel.kt:1821)
at kotlinx.coroutines.io.ByteBufferChannel.readUTF8LineToUtf8Suspend(ByteBufferChannel.kt:2113)
at kotlinx.coroutines.io.ByteBufferChannel.readUTF8LineToAscii(ByteBufferChannel.kt:2053)
at kotlinx.coroutines.io.ByteBufferChannel.readUTF8LineTo(ByteBufferChannel.kt:2141)
at kotlinx.coroutines.io.ByteBufferChannel.readUTF8Line(ByteBufferChannel.kt:2145)
at kotlinx.coroutines.io.ByteReadChannelKt.readUTF8Line(ByteReadChannel.kt:189)
at io.ktor.sessions.SessionTrackerById$load$2.invokeSuspend(SessionTrackerById.kt:31)
at io.ktor.sessions.SessionTrackerById$load$2.invoke(SessionTrackerById.kt)
at io.ktor.sessions.CacheStorage.read(CacheStorage.kt:17)
at io.ktor.sessions.SessionTrackerById.load(SessionTrackerById.kt:30)
at io.ktor.sessions.Sessions$Feature$install$1.invokeSuspend(Sessions.kt:45)
at io.ktor.sessions.Sessions$Feature$install$1.invoke(Sessions.kt)
at io.ktor.util.pipeline.SuspendFunctionGun.loop(PipelineContext.kt:278)
at io.ktor.util.pipeline.SuspendFunctionGun.access$loop(PipelineContext.kt:63)
at io.ktor.util.pipeline.SuspendFunctionGun.proceed(PipelineContext.kt:137)
at io.ktor.features.StatusPages$interceptCall$2.invokeSuspend(StatusPages.kt:94)
at io.ktor.features.StatusPages$interceptCall$2.invoke(StatusPages.kt)
at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:91)
at kotlinx.coroutines.CoroutineScopeKt.coroutineScope(CoroutineScope.kt:186)
at io.ktor.features.StatusPages.interceptCall(StatusPages.kt:93)
at io.ktor.features.StatusPages$Feature$install$2.invokeSuspend(StatusPages.kt:133)
at io.ktor.features.StatusPages$Feature$install$2.invoke(StatusPages.kt)
at io.ktor.util.pipeline.SuspendFunctionGun.loop(PipelineContext.kt:278)
at io.ktor.util.pipeline.SuspendFunctionGun.access$loop(PipelineContext.kt:63)
at io.ktor.util.pipeline.SuspendFunctionGun.proceed(PipelineContext.kt:137)
at io.ktor.features.CallLogging$Feature$install$2.invokeSuspend(CallLogging.kt:130)
at io.ktor.features.CallLogging$Feature$install$2.invoke(CallLogging.kt)
at io.ktor.util.pipeline.SuspendFunctionGun.loop(PipelineContext.kt:278)
at io.ktor.util.pipeline.SuspendFunctionGun.access$loop(PipelineContext.kt:63)
at io.ktor.util.pipeline.SuspendFunctionGun.proceed(PipelineContext.kt:137)
at io.ktor.util.pipeline.SuspendFunctionGun.execute(PipelineContext.kt:157)
at io.ktor.util.pipeline.Pipeline.execute(Pipeline.kt:23)
at io.ktor.server.engine.DefaultEnginePipelineKt$defaultEnginePipeline$2.invokeSuspend(DefaultEnginePipeline.kt:106)
at io.ktor.server.engine.DefaultEnginePipelineKt$defaultEnginePipeline$2.invoke(DefaultEnginePipeline.kt)
at io.ktor.util.pipeline.SuspendFunctionGun.loop(PipelineContext.kt:278)
at io.ktor.util.pipeline.SuspendFunctionGun.access$loop(PipelineContext.kt:63)
at io.ktor.util.pipeline.SuspendFunctionGun.proceed(PipelineContext.kt:137)
at io.ktor.util.pipeline.SuspendFunctionGun.execute(PipelineContext.kt:157)
at io.ktor.util.pipeline.Pipeline.execute(Pipeline.kt:23)
at io.ktor.server.jetty.JettyKtorHandler$handle$2.invokeSuspend(JettyKtorHandler.kt:96)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:32)
at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:233)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
```
Not sure if this belongs here or to kotlinx.serialization.
Contributor guide
Research direction
Start with io.ktor.sessions.SessionTrackerById.load in SessionTrackerById.kt and CacheStorage.read in CacheStorage.kt, using the stack trace to trace the session data read. Reproduce the failure with a long session and determine whether the malformed byte originates in Ktor's session cache or kotlinx.io. Done means the source of the illegal trailing byte is identified and the long-session case is covered by a verified fix or clear upstream report.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100