question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Serialization of Authentication object into Redis session no longer works

See original GitHub issue

Expected Behavior

Serialization of attributes into Redis session works as before.

Actual Behaviour

It somehow does not populate attributes into Authentication object:

Unexpected error occurred: null
java.lang.NullPointerException: null
	at java.util.HashMap.putMapEntries(HashMap.java:497)
	at java.util.HashMap.<init>(HashMap.java:486)
	at io.micronaut.security.authentication.ClientAuthentication.getAttributes(ClientAuthentication.java:64)
	at xxx.server.utils.extensions.AuthenticationExtensionsKt.getAccountId(AuthenticationExtensions.kt:11)
	at xxx.server.controllers.api.SessionController.getSession(SessionController.kt:36)
	at xxx.server.controllers.api.$SessionController$Definition$Intercepted.$$access$$getSession(Unknown Source)
	at xxx.server.controllers.api.$SessionController$Definition$Exec.dispatch(Unknown Source)
	at io.micronaut.context.AbstractExecutableMethodsDefinition$DispatchedExecutableMethod.invoke(AbstractExecutableMethodsDefinition.java:378)
	at io.micronaut.aop.chain.MethodInterceptorChain.proceed(MethodInterceptorChain.java:128)
	at io.micronaut.transaction.interceptor.TransactionalInterceptor.intercept(TransactionalInterceptor.java:196)
	at io.micronaut.aop.chain.MethodInterceptorChain.proceed(MethodInterceptorChain.java:137)
	at xxx.server.controllers.api.$SessionController$Definition$Intercepted.getSession(Unknown Source)
	at xxx.server.controllers.api.$SessionController$Definition$Exec.dispatch(Unknown Source)
	at io.micronaut.context.AbstractExecutableMethodsDefinition$DispatchedExecutableMethod.invoke(AbstractExecutableMethodsDefinition.java:378)
	at io.micronaut.context.DefaultBeanContext$4.invoke(DefaultBeanContext.java:583)
	at io.micronaut.web.router.AbstractRouteMatch.execute(AbstractRouteMatch.java:303)
	at io.micronaut.web.router.RouteMatch.execute(RouteMatch.java:111)
	at io.micronaut.http.context.ServerRequestContext.with(ServerRequestContext.java:103)
	at io.micronaut.http.server.RouteExecutor.lambda$executeRoute$14(RouteExecutor.java:659)
	at reactor.core.publisher.FluxDeferContextual.subscribe(FluxDeferContextual.java:49)
	at reactor.core.publisher.InternalFluxOperator.subscribe(InternalFluxOperator.java:62)
	at reactor.core.publisher.FluxSubscribeOn$SubscribeOnSubscriber.run(FluxSubscribeOn.java:194)
	at io.micronaut.reactive.reactor.instrument.ReactorInstrumentation.lambda$null$0(ReactorInstrumentation.java:62)
	at reactor.core.scheduler.WorkerTask.call(WorkerTask.java:84)
	at reactor.core.scheduler.WorkerTask.call(WorkerTask.java:37)
	at io.micronaut.scheduling.instrument.InvocationInstrumenterWrappedCallable.call(InvocationInstrumenterWrappedCallable.java:53)
	at java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.lang.Thread.run(Thread.java:829)
	at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:597)
	at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:194)

Steps To Reproduce

Micronaut team has a sample application in micronaut-graal-tests, which can be simply modified to reproduci this behaviour: https://github.com/micronaut-graal-tests/micronaut-security-session-graal

Append to application.yml:

---
redis:
  url: redis://127.0.0.1:6379
micronaut:
  session:
    http:
      redis:
        enabled: true

Add dependency to build.gradle:

implementation("io.micronaut.redis:micronaut-redis-lettuce")

You need to have Redis running on specified url for this test.

Environment Information

GraalVM 22.1

Example Application

No response

Version

3.5.1

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
yawkatcommented, Jun 14, 2022

the regression happened because prior to 3.1.x the request context was not available in the lettuce reactive handler. My guess is that this changed in one of @dstepanov’s improvements to reactive context propagation. I’m not going to bother tracking down the specific change, since it’s certainly better for the request context. I’ll work on a fix on the security side instead.

0reactions
yawkatcommented, Jun 13, 2022

ok i can see that it works with 3.0.x, i will look at why tomorrow.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring Boot with Session/Redis Serialization Error with Bad ...
The Java object to be cached must implement the serializable interface, because spring will serialize the object and store it in redis.
Read more >
Unreadable session after serialization · Issue #361 - GitHub
I use Spring session with a Redis repository. ... It works fine but I the session attributes that are storred in Redis are...
Read more >
Handling Deserialization errors in Spring Redis Sessions
This blog post discusses a method to work around this issue. ... This happens because the serialized object in the session and the...
Read more >
Express session middleware
Forces a session that is “uninitialized” to be saved to the store. A session is uninitialized when it is new but not modified....
Read more >
Token cache serialization (MSAL.NET) - Microsoft Entra
A shared cache is faster because it's not serialized. ... Use an in-memory token cache in apps that participate in machine-to-machine auth ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found