Skip to content

ensures Payload released in LimitingFlowCollector #172

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 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ internal class LimitingFlowCollector(
}

override suspend fun emit(value: Payload): Unit = value.closeOnError {
useRequest()
try {
useRequest()
} catch (t: Throwable) {
value.release()
throw t
}
state.send(NextPayloadFrame(streamId, value))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ internal class TcpConnection(private val socket: Socket) : Connection, Coroutine
private val receiveChannel = SafeChannel<ByteReadPacket>(8)

init {
val channelCloseJob = Job(job)
launch {
socket.openWriteChannel(autoFlush = true).use {
while (isActive) {
Expand Down Expand Up @@ -77,6 +78,14 @@ internal class TcpConnection(private val socket: Socket) : Connection, Coroutine
val error = cause?.let { it as? CancellationException ?: CancellationException("Connection failed", it) }
sendChannel.cancel(error)
receiveChannel.cancel(error)
CoroutineScope(job).launch {
while (!sendChannel.isClosedForReceive || !sendChannel.isClosedForSend
|| !receiveChannel.isClosedForReceive || !receiveChannel.isClosedForSend
) {
delay(1)
}
channelCloseJob.complete()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,19 @@ internal constructor(
val clientChannel = SafeChannel<ByteReadPacket>(Channel.UNLIMITED)
val serverChannel = SafeChannel<ByteReadPacket>(Channel.UNLIMITED)
val connectionJob = Job(job)
val channelCloseJob = Job(job)
connectionJob.invokeOnCompletion {
val error = CancellationException("Connection failed", it)
clientChannel.cancel(error)
serverChannel.cancel(error)
CoroutineScope(job).launch {
while (!clientChannel.isClosedForReceive || !clientChannel.isClosedForSend
|| !serverChannel.isClosedForReceive || !serverChannel.isClosedForSend
) {
delay(1)
}
channelCloseJob.complete()
}
}
val clientConnection = LocalConnection(serverChannel, clientChannel, pool, connectionJob)
val serverConnection = LocalConnection(clientChannel, serverChannel, pool, connectionJob)
Expand Down