Skip to content

Kotlin Coroutines server impl: unable to use aspects due to CGLIB and final "context" property #261

@Viachaslau-Zinkevich

Description

@Viachaslau-Zinkevich

For Kotlin Coroutines service/server implementations generated code uses io.grpc.kotlin.AbstractCoroutineServerImpl.
As GRPC generator doesn't create any service interfaces, Spring's AutoProxy aspect weaver cannot use JDK proxies and falls back to CGLIB.
io.grpc.kotlin.AbstractCoroutineServerImpl uses val context: CoroutineContext which is a non-open non-overridable property which generates final getter. This results in a situation when CGLIB must generate a new field and doesn't delegate getter call to original proxied target, thus having context set to null.
Having context = null fails generated *CoroutineImplBase#bindService implementations, which expects this.couroutine to be non-null.

Making context as open val context in io.grpc.kotlin.AbstractCoroutineServerImpl will potentially fix the issue as it will allow override and extensions for CGLIB.

In the long run ideally I believe the generated service must have interfaces, to avoid such problems in future and do not depend on abstract classes.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions