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

ReaderJob & WriterJob leak in TLS socket and prevent context from completion #3557

Closed
olehs opened this issue Apr 20, 2023 · 3 comments
Closed

Comments

@olehs
Copy link

olehs commented Apr 20, 2023

override fun attachForReading(channel: ByteChannel): WriterJob =
writer(coroutineContext + CoroutineName("cio-tls-input-loop"), channel) {
appDataInputLoop(this.channel)
}
override fun attachForWriting(channel: ByteChannel): ReaderJob =
reader(coroutineContext + CoroutineName("cio-tls-output-loop"), channel) {
appDataOutputLoop(this.channel)
}

Jobs created by these two methods should be cancelled when socket is closed

@Nek-12
Copy link

Nek-12 commented Jul 11, 2023

I don't know how did you manage to create an issue here since new issues lead to JetBrains issuetracker, but I think you should move it there

@rmmcosta
Copy link

Does this issue still makes sense after the #3690 fix?

@olehs
Copy link
Author

olehs commented Nov 30, 2023

I didn't track latest changes as we used a workaround (see below), so can't say for sure. I'll check it and if any issues appear, report them in a new topic.

    private class TLSSocket(private val tlsSocket: Socket) : Socket by tlsSocket {
        private var readerJob: ReaderJob? = null
        private var writerJob: WriterJob? = null

        override fun attachForReading(channel: ByteChannel): WriterJob {
            return tlsSocket.attachForReading(channel).also {
                writerJob = it
            }
        }

        override fun attachForWriting(channel: ByteChannel): ReaderJob {
            return tlsSocket.attachForWriting(channel).also {
                readerJob = it
            }
        }

        override fun close() {
            readerJob?.cancel()
            writerJob?.cancel()
        }
    }

Thank you

@olehs olehs closed this as completed Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants