-
Notifications
You must be signed in to change notification settings - Fork 28
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
Wrapped ByteStreams fail when used as streaming request bodies #613
Comments
As noted by @aajtodd the reason for the hang while signing is likely an incomplete implementation of the fallback case for stream reading. Specifically, the read channel needs to be read into the Updating the code to this: internal suspend fun SdkByteReadChannel.readAvailableFallback(dest: SdkByteBuffer, limit: Long): Long {
if (availableForRead == 0) awaitContent()
// channel was closed while waiting and no further content was made available
if (availableForRead == 0 && isClosedForRead) return -1
val tmp = ByteArray(minOf(availableForRead.toLong(), limit, Int.MAX_VALUE.toLong()).toInt())
readFully(tmp) // *** NEW LINE ***
dest.writeFully(tmp)
return tmp.size.toLong()
} Causes signing to complete successfully and sending to begin but not succeed. Now the read channel is getting cancelled somehow after reading a subset of the stream contents. A
This exception appears to be thrown in |
I was seeing a different issue but I suspect it's similar root cause after fixing the fallback implementation. The wrapped stream still has to supply a val wrappedStream = object : ByteStream.ReplayableStream() {
+ override val contentLength: Long = file.size.toLong()
override fun newReader(): SdkByteReadChannel {
val underlyingReader = underlyingStream.newReader()
return object : SdkByteReadChannel by underlyingReader
}
} @ianbotsf can you verify adding an explicit content length to the wrapped stream resolves the issue you were seeing? |
Yes it does, although it was not apparent that custom/proxied streams must provide a content length because the field is |
Describe the bug
Streaming request operations (e.g., S3
PutObject
) require usingByteStream
instances. UsingByteStream
instances which return readers that directly wrap Ktor channels works correctly (e.g.,ByteStream.fromFile(...)
). Attempting to wrap those streams, even without adding any additional logic, fails. Specifically, the stream appears to hang and never complete signing.Expected Behavior
Wrapped
ByteStream
instances should be usable as streaming request bodies.Steps to Reproduce
The following example demonstrates the problem:
The text was updated successfully, but these errors were encountered: