Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/fix-byte-stream-source-leak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"client-sdk-android": patch
---

Fixed file descriptor leak in ByteStreamSender where Source was not closed after reading.
Original file line number Diff line number Diff line change
Expand Up @@ -86,25 +86,28 @@ suspend fun ByteStreamSender.write(input: InputStream): Result<Unit> {

/**
* Reads the source and sends it to the data stream.
*
* The source will be closed when this function completes, whether it succeeds or fails.
*/
@CheckResult
suspend fun ByteStreamSender.write(source: Source): Result<Unit> {
val buffer = Buffer()
while (true) {
try {
val readLen = source.read(buffer, 4096)
if (readLen == -1L) {
break
}
return try {
source.use { src ->
val buffer = Buffer()
while (true) {
val readLen = src.read(buffer, 4096)
if (readLen == -1L) {
break
}

val result = write(buffer.readByteArray())
if (result.isFailure) {
return result
val result = write(buffer.readByteArray())
if (result.isFailure) {
return@use result
}
}
} catch (e: Exception) {
return Result.failure(e)
Result.success(Unit)
}
} catch (e: Exception) {
Result.failure(e)
}

return Result.success(Unit)
}