Skip to content
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

Memory leak #207

Open
ponktacology opened this issue Sep 24, 2024 · 1 comment
Open

Memory leak #207

ponktacology opened this issue Sep 24, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@ponktacology
Copy link

ponktacology commented Sep 24, 2024

Describe the bug
The RPC services are leaking memory. In the example below the Args and Response objects are never cleared by the GC.

To Reproduce
Steps to reproduce the behavior:

Example code:

@Serializable
data class Args(val name: String)
@Serializable
data class Response(val response: String)
interface TestService : RPC {
    suspend fun test(args: Args): Response
}
object TestServer {

    class TestServiceImpl(override val coroutineContext: CoroutineContext) : TestService {
        override suspend fun test(args: Args): Response {
            return Response("Hello ${args.name} back")
        }
    }

    @JvmStatic
    fun main(args: Array<String>) {
        embeddedServer(
            Netty,
            host = "0.0.0.0",
            port = 1337
        ) {
            install(RPC) {
                serialization {
                    json()
                }
            }
            routing {
                rpc("/test") {
                    registerService<TestService> { ctx -> TestServiceImpl(ctx) }
                }
            }
        }.start(true)
    }
}
object TestClient {

    @JvmStatic
    fun main(args: Array<String>) {
        runBlocking {
            val ktorClient = HttpClient(CIO) {
                install(WebSockets)
            }
            val client = ktorClient.rpc {
                url {
                    host = "0.0.0.0"
                    port = 1337
                    encodedPath = "/test"
                }
                rpcConfig {
                    serialization {
                        json()
                    }
                }
            }
            val service = client.withService<TestService>()
            var i = 0
            while (true) {
                val response = service.test(Args("Name #${i++}"))
                println(response)
                delay(1)
            }
        }
    }
}

Expected behavior
No memory leaks

Additional context
Inspected with VisualVM, even after the GC Args and Response objects stay in the memory and the process eventually throws OutOfMemory

@ponktacology ponktacology added the bug Something isn't working label Sep 24, 2024
@Mr3zee
Copy link
Collaborator

Mr3zee commented Oct 8, 2024

Hey, @ponktacology ! I tried reproducing the leak scenario, but was not able to do so, checked as well with the visual VM.
Can you, please, provide a git repo and exact steps to reproduce it?

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

No branches or pull requests

2 participants