Skip to content

Commit

Permalink
fixup! KTOR-8105 Fix for concurrent flush attempts breaking CIO clien…
Browse files Browse the repository at this point in the history
…t (again)
  • Loading branch information
bjhham committed Feb 14, 2025
1 parent 89c85e0 commit 37f17f5
Showing 1 changed file with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,26 @@ internal class TLSClientHandshake(
rawOutput.writeRecord(record)
} catch (cause: Throwable) {
channel.close(cause)
break
}
}
}.apply {
invokeOnClose {
launch(CoroutineName("cio-tls-closer")) {
val closeRecord = TLSRecord(
TLSRecordType.Alert,
packet = buildPacket {
writeByte(TLSAlertLevel.WARNING.code.toByte())
writeByte(TLSAlertType.CloseNotify.code.toByte())
}
)
val record = if (useCipher) cipher.encrypt(closeRecord) else closeRecord
rawOutput.writeRecord(record)
rawOutput.flushAndClose()
closeTask.complete()
try {
val closeRecord = TLSRecord(
TLSRecordType.Alert,
packet = buildPacket {
writeByte(TLSAlertLevel.WARNING.code.toByte())
writeByte(TLSAlertType.CloseNotify.code.toByte())
}
)
val record = if (useCipher) cipher.encrypt(closeRecord) else closeRecord
rawOutput.writeRecord(record)
rawOutput.flushAndClose()
} finally {
closeTask.complete()
}
}
}
}
Expand Down

0 comments on commit 37f17f5

Please sign in to comment.