"An error occurred while pushing a context" error occurs when using RequestContextHooks.enable()
See original GitHub issueApplication using RequestContextHooks.enable()
for log tracking, and if many requests come in at the same time, An error occurred while pushing a context
error occurs.
In the service, it occurs in the action of querying with r2dbc jooq. I’m not sure sample code below is the same cause, but the same error occurs.
version info
kotlin 1.7.20
armeria-logback : 1.20.1
armeria-reactor3: 1.20.1
kotlinx-coroutines-core-jvm: 1.6.4
kotlinx-coroutines-reactive: 1.6.4
kotlinx-coroutines-reactor: 1.6.4
Error log
Caused by: java.lang.IllegalStateException: Trying to call object wrapped with context [sreqId=8d41eecd, chanId=96523267, raddr=127.0.0.1:57795, laddr=127.0.0.1:8080][h1c://gimnamjung-ui-macbookpro.local/v1/players/test/%ED%95%9C%EB%8F%99%EA%B7%B8%EB%9D%BC%EB%AF%B8#GET], but context is currently set to [sreqId=673c702e, chanId=7a3518ba, raddr=127.0.0.1:57796, laddr=127.0.0.1:8080][h1c://gimnamjung-ui-macbookpro.local/v1/players/test/%ED%95%9C%EB%8F%99%EA%B7%B8%EB%9D%BC%EB%AF%B8#GET]. This means the callback was called from unexpected thread or forgetting to close previous context.
Sample Code
// TestAnnotatedService
@Get("/test")
suspend fun test(): Long? {
return testService.test()
}
// TestService
private val mutex = Mutex() // kotlinx.coroutines.sync
suspend fun test(): Long? {
return mutex.withLock {
Mono.just(1L)
.awaitSingle()
}
}
Issue Analytics
- State:
- Created a year ago
- Comments:12 (6 by maintainers)
Top Results From Across the Web
Reactor should use context for when subscriber is created, not ...
Our hooks store the context when the publisher is created. So the thread that calls publisher.subscribe() does not have to have ctx in...
Read more >Index (Armeria 1.7.2 API reference) - Javadoc.io
Enables cookies to be added to CORS requests. allowedRequestHeaders() - Method in annotation type com.linecorp.armeria.server.annotation.decorator.
Read more >Allow to bind KafkaClientMetrics for each decaton consumer
Always bind KafkaClientMetrics , tagged with the right subscription id. This should not be a breaking change since there is no reasonable way...
Read more >Line Armeria Statistics & Issues - Codesti
"An error occurred while pushing a context" error occurs when using RequestContextHooks.enable(), open, 12, 2022-10-22, 2022-11-20, -.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I found one possible workaround. It’s using
ArmeriaRequestCoroutinContext
explicitly withGlobalScope.async
:Sorry about the late response. 😓
Yes, exactly. When there’re two concurrent requests A and B, the thread for A also runs the block for the request B which then:
Mono
is created with theaContext
by the hookMono
raises an exception when it subscribed with thebContext
.I guess not using the
RequestContextHooks
and push the context manually where it needs is the best way we can do for now. 😢 I’m thinking of adding a global hook that is removing theRequestContext
in thread-local and pushing it back when the continuation is resumed but I’m not sure if it’s really possible. Let me get back to this issue when I find the solution. 🙇