aws-sdk-kotlin icon indicating copy to clipboard operation
aws-sdk-kotlin copied to clipboard

Occasional "Channel has been cancelled" when upload large file

Open vcanuel opened this issue 3 years ago • 5 comments

Describe the bug

I have an error when I upload large file (but not always..)

I thought this was fixed with https://github.com/awslabs/smithy-kotlin/pull/624 but this seems the same issue as https://youtrack.jetbrains.com/issue/KTOR-1054

Expected behavior

No error

Current behavior

My upload is canceled with the following error :

Exception in thread "OkHttp Dispatcher" java.util.concurrent.CancellationException: Channel has been cancelled
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
       .....
	at io.ktor.client.engine.okhttp.StreamRequestBody.writeTo(StreamRequestBody.kt:21)
Caused by: java.util.concurrent.CancellationException: Channel has been cancelled
	at io.ktor.utils.io.ByteBufferChannel.cancel(ByteBufferChannel.kt:180)
	at io.ktor.utils.io.ByteReadChannelKt.cancel(ByteReadChannel.kt:231)
	at io.ktor.utils.io.jvm.javaio.InputAdapter.close(Blocking.kt:73)
	at okio.InputStreamSource.close(JvmOkio.kt:108)
	at kotlin.io.CloseableKt.closeFinally(Closeable.kt:60)
	at io.ktor.client.engine.okhttp.StreamRequestBody.writeTo(StreamRequestBody.kt:20)
	... 15 more

Steps to Reproduce

Upload a large file :

private suspend fun putS3(): UploadResult { 
    val file = File("largeFile.pdf")
    
    val putRequest = PutObjectRequest {
	    bucket = outputS3Bucket
	    key = "$outputS3Prefix/myfile.json"
	    body = ByteStream.fromFile(file)
    }
    
       val uploadResponse = amazonS3ClientKt.putObject(request)
        return  UploadSuccess(bucketName, objectKey, MediaMetadata(fileName, uploadResponse.eTag))
}

Possible Solution

No response

Context

No response

AWS Kotlin SDK version used

0.14.4-beta

Platform (JVM/JS/Native)

JVM

Operating System and version

Mac OS 12.3.1 - Open JDK 17

vcanuel avatar Apr 29 '22 14:04 vcanuel

@vcanuel Thanks for reporting this.

Anything else you can share about the operation in question? File size? Any debug/trace logs you may have gathered?

I'll take a look and see if I can reproduce it.

aajtodd avatar May 02 '22 18:05 aajtodd

I've been able to see a similar exception only a few times in trying to recreate this.

Is this error bubbling up to an exception you see or is it just showing up in your logs?

aajtodd avatar May 06 '22 15:05 aajtodd

I have been able to reproduce this only a handful of times but not been able to track down any rhyme or reason for it.

Our next short term step here is to enable additional logging to aid in tracking down a root cause. This will be available hopefully in the next release and I'll update instructions here when available.


The only issue that looked semi related if you squint hard enough is this okhttp issue.

Indeed several of the times that I was able to reproduce this the underlying cause seemed to be timeout related but there wasn't enough there to discern anything else useful. I'm putting this in the ticket as noteworthy and something to look into closer pending what additional telemetry turns up.

aajtodd avatar May 18 '22 21:05 aajtodd

Hi, Thanks for your time on this issue. I have no more information than those initially provided, the operation is PutObjectRequest and I have extracted the relevant log. I usually reproduce this issue locally with localstack and a large file (> 1go). In production, we did not notice new occurrence of this bug.

vcanuel avatar May 24 '22 13:05 vcanuel

Ok thanks for the update. The additional logging should be available in the next release (sometime this week). I'll update here when available. I'll also look into trying to recreate with localstack.

aajtodd avatar May 24 '22 13:05 aajtodd

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.

github-actions[bot] avatar Sep 21 '22 07:09 github-actions[bot]