Skip to content

Propagate transport coroutine context #374

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 4, 2025
Merged

Conversation

yakivy
Copy link
Contributor

@yakivy yakivy commented Jul 2, 2025

Issue: #226

@Mr3zee Mr3zee self-requested a review July 2, 2025 13:02
Copy link
Collaborator

@Mr3zee Mr3zee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @yakivy ! Thank you for this PR! It looks good, I have only one comment for the code, please see below.

Can I also please ask you to clean the history in the branch, remove merge commit and make two commits - one for the change and one for the tests?

Otherwise looks good, I'll run the tests after changes and if everything passes - we'll merge it!

@Mr3zee Mr3zee linked an issue Jul 2, 2025 that may be closed by this pull request
@Mr3zee Mr3zee added the bug Something isn't working label Jul 2, 2025
@yakivy yakivy requested a review from Mr3zee July 2, 2025 13:56
@Mr3zee
Copy link
Collaborator

Mr3zee commented Jul 2, 2025

@yakivy stacktrace from Apple/Windows builds for your new test:

kotlin.IllegalStateException: Current context doesn't contain Job in it: CoroutineElement(value=transport)
  at kotlin.Throwable#<init>(Unknown Source)
  at kotlin.Exception#<init>(Unknown Source)
  at kotlin.RuntimeException#<init>(Unknown Source)
  at kotlin.IllegalStateException#<init>(Unknown Source)
  at kotlinx.coroutines#<get-job>__at__kotlin.coroutines.CoroutineContext(Unknown Source)
  at kotlinx.rpc.krpc.test.LocalTransport#<init>(Unknown Source)
  at kotlinx.rpc.krpc.test.CoroutineContextPropagationTest.CoroutineContextPropagationTest$test$1.$invokeCOROUTINE$0.invokeSuspend#internal(Unknown Source)
  at kotlinx.rpc.krpc.test.CoroutineContextPropagationTest.CoroutineContextPropagationTest$test$1.invoke#internal(Unknown Source)
  at kotlin.coroutines.SuspendFunction1#invoke#suspend(Unknown Source)
  at kotlinx.coroutines.test.runTest$$inlined$let$1.runTest$$inlined$let$1$invoke$2.$invokeCOROUTINE$0.invokeSuspend#internal(Unknown Source)
  at kotlin.coroutines.native.internal.BaseContinuationImpl#invokeSuspend(Unknown Source)
  at kotlin.coroutines.native.internal.BaseContinuationImpl#resumeWith(Unknown Source)
  at kotlin.coroutines.Continuation#resumeWith(Unknown Source)
  at kotlinx.coroutines.DispatchedTask#run(Unknown Source)
  at kotlinx.coroutines.Runnable#run(Unknown Source)
  at kotlinx.coroutines.test.TestDispatcher#processEvent(Unknown Source)
  at kotlinx.coroutines.test.TestCoroutineScheduler#tryRunNextTaskUnless(Unknown Source)
  at kotlinx.coroutines.test.runTest$$inlined$let$1.runTest$$inlined$let$1$invoke$3.$invokeCOROUTINE$1.invokeSuspend#internal(Unknown Source)
  at kotlinx.coroutines.test.runTest$$inlined$let$1.runTest$$inlined$let$1$invoke$3.invoke#internal(Unknown Source)
  at kotlin.Function2#invoke(Unknown Source)
  at kotlin.coroutines.intrinsics.createCoroutineUnintercepted$$inlined$createCoroutineFromSuspendFunction$2.invokeSuspend#internal(Unknown Source)
  at kotlin.coroutines.native.internal.BaseContinuationImpl#invokeSuspend(Unknown Source)
  at kotlin.coroutines.native.internal.BaseContinuationImpl#resumeWith(Unknown Source)
  at kotlin.coroutines.Continuation#resumeWith(Unknown Source)
  at kotlinx.coroutines.DispatchedTask#run(Unknown Source)
  at kotlinx.coroutines.Runnable#run(Unknown Source)
  at kotlinx.coroutines.EventLoopImplBase#processNextEvent(Unknown Source)
  at kotlinx.coroutines.EventLoop#processNextEvent(Unknown Source)
  at kotlinx.coroutines.BlockingCoroutine.joinBlocking#internal(Unknown Source)
  at kotlinx.coroutines#runBlocking(Unknown Source)
  at kotlinx.coroutines#runBlocking$default(Unknown Source)
  at kotlinx.coroutines.test#createTestResult(Unknown Source)
  at kotlinx.coroutines.test#runTest__at__kotlinx.coroutines.test.TestScope(Unknown Source)
  at kotlinx.coroutines.test#runTest(Unknown Source)
  at kotlinx.coroutines.test#runTest$default(Unknown Source)
  at kotlinx.rpc.krpc.test.CoroutineContextPropagationTest#test(Unknown Source)
  at kotlinx.rpc.krpc.test.$CoroutineContextPropagationTest$test$0.$CoroutineContextPropagationTest$test$0$$FUNCTION_REFERENCE_FOR$test$0.invoke#internal(Unknown Source)
  at kotlinx.rpc.krpc.test.$CoroutineContextPropagationTest$test$0.$CoroutineContextPropagationTest$test$0$$FUNCTION_REFERENCE_FOR$test$0.$<bridge-DNN>invoke(Unknown Source)
  at kotlin.Function1#invoke(Unknown Source)
  at kotlin.native.internal.test.BaseClassSuite.TestCase#doRun(Unknown Source)
  at kotlin.native.internal.test.TestCase#doRun(Unknown Source)
  at kotlin.native.internal.test.TestCase#run(Unknown Source)
  at kotlin.native.internal.test.TestCase#run(Unknown Source)
  at kotlin.native.internal.test.TestRunner.run#internal(Unknown Source)
  at kotlin.native.internal.test.TestRunner.runIteration#internal(Unknown Source)
  at kotlin.native.internal.test.TestRunner#run(Unknown Source)
  at kotlin.native.internal.test#testLauncherEntryPoint(Unknown Source)
  at kotlin.native.internal.test#main(Unknown Source)
  at <global>.Konan_start(Unknown Source)
  at <global>.Init_and_run_start(Unknown Source)
  at <global>.__tmainCRTStartup(Unknown Source)
  at <global>.mainCRTStartup(Unknown Source)
  at <global>._ZSt25__throw_bad_function_callv(Unknown Source)
  at <global>._ZSt25__throw_bad_function_callv(Unknown Source)

PLease also run detekt command

@Mr3zee
Copy link
Collaborator

Mr3zee commented Jul 2, 2025

Same exception for Java, Js, Wasm, Linux

@yakivy
Copy link
Contributor Author

yakivy commented Jul 3, 2025

@Mr3zee could you take a look once more please?

@Mr3zee
Copy link
Collaborator

Mr3zee commented Jul 3, 2025

@yakivy everything seems fine fine except for detekt. Please fix its errors

@yakivy
Copy link
Contributor Author

yakivy commented Jul 3, 2025

@Mr3zee sorry, could you give some details, command finished successfully on my machine:

./gradlew detekt
Configuration on demand is an incubating feature.
Calculating task graph as configuration cache cannot be reused because output of the external process 'git' has changed.
Type-safe project accessors is an incubating feature.

> Configure project :gradle-plugin
WARNING: Unsupported Kotlin plugin version.
The `embedded-kotlin` and `kotlin-dsl` plugins rely on features of Kotlin `2.0.21` that might work differently than in the requested version `2.2.0`.
[Gradle Plugin] kotlinx.rpc project version: 0.8.0

> Configure project :compiler-plugin
[Compiler Plugin] kotlinx.rpc project version: 2.2.0-0.8.0, Kotlin version: 2.2.0, Compiler version: 2.2.0

> Configure project :dokka-plugin
[Dokka Plugin] kotlinx.rpc project version: 0.8.0, Kotlin version: 2.2.0

> Configure project :
[Core] kotlinx.rpc project version: 0.8.0, Kotlin version: 2.2.0, Compiler: 2.2.0

BUILD SUCCESSFUL in 6s
48 actionable tasks: 48 up-to-date

Did I miss something?

@Mr3zee
Copy link
Collaborator

Mr3zee commented Jul 3, 2025

@yakivy it shouldn't fail the build, but should produce warnings. Maybe they are cached for a rerun, try to do a code change and run again.

@yakivy
Copy link
Contributor Author

yakivy commented Jul 3, 2025

@Mr3zee I do not see any warning on my machine except the one from "gradle-plugin", can you trigger workflow so I can check warnings there? or maybe you can give me an example of warning from your output?

@Mr3zee
Copy link
Collaborator

Mr3zee commented Jul 3, 2025

@yakivy Here is the detekt report from the CI:

krpc-test.html.zip

@yakivy
Copy link
Contributor Author

yakivy commented Jul 3, 2025

@Mr3zee pull from this branch again, you are on HEAD~1 commit

@Mr3zee
Copy link
Collaborator

Mr3zee commented Jul 4, 2025

Yes, you are right, some of them are outdated.
This one is valid though:

if (parentContext != null) parentContext + it else it

Should be changed to

if (parentContext != null) { 
    parentContext + it 
} else { 
    it 
}

Also please check that CoroutineContextPropagationTest.kt ends with an empty line, I'm not sure github shows it even when it is present

@yakivy
Copy link
Contributor Author

yakivy commented Jul 4, 2025

Sorry, @Mr3zee do you have custom rules?
Detekt config in the repo allows single line statements without braces:

  BracesOnIfStatements:
    active: true
    singleLine: 'never'
    multiLine: 'always'

And CoroutineContextPropagationTest already ends with a new line. Here is the report:
image

@Mr3zee
Copy link
Collaborator

Mr3zee commented Jul 4, 2025

@yakivy my bad, maybe I remember incorrectly, will rerun the check

@Mr3zee
Copy link
Collaborator

Mr3zee commented Jul 4, 2025

Yep, it works, sorry for the confusion

@Mr3zee
Copy link
Collaborator

Mr3zee commented Jul 4, 2025

@yakivy thank for your contribution! It will be in 0.8.1 next week

@Mr3zee Mr3zee merged commit c4a5721 into Kotlin:main Jul 4, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RPC Server Service loses transport coroutine context
2 participants