-
Notifications
You must be signed in to change notification settings - Fork 119
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
AWS Amplify Storage HttpErrorCode(SOCKET_TIMEOUT) #2745
Comments
Hi @xaluxs Just to confirm, this issue is causing a fatal crash that is force closing the application? I'll do my best to replicate. The PartUploadTransferWorker has a try/catch around the worker executing the request. Its possible this crash is occurring at a lower level than Amplify and we are unable to catch it. I'll look to replicate and notify our Kotlin SDK team if we are unable to prevent the crash on our end. |
This issue is now closed. Comments on closed issues are hard for our team to see. |
@xaluxs I saw a response come in and then it appears to have been deleted and the issue closed. Was this intentional? I want to make sure that we are properly able to track this potential issue. |
Hi @tylerjroach Sorry I closed this by mistake but it's still happening, And in answer to your question, yes, it is causing a fatal crash that forces you to close the application. As an additional addition, I have noticed that it happens more frequently when, for example, in my tests there are more than 10 requests in queue and the connection is very slow, I simulate it with Proxyman, but it also happens using data or a slow connection. WiFi connection. |
Thanks for the additional info. I'll try and simulate this as well |
@xaluxs I was able to replicate the stacktrace you provided exactly, but it is not crashing the application. I see logs after the error is thrown in logs where the result is provided to me as failed. Are you sure this isn't just an error log? Do you have any logs after what you have provided that may indicacate something else causing the crash? |
@tylerjroach I replicated it again, I have 10 photos queued with a slow network, I do several forced reloads, wait a couple of minutes and then it starts throwing errors.
in case it exists. I leave a video replicating, as well as a log where the crash begins, it seems that this time it was with:
Ampliy.Crash.mp4net config: |
Looking at the stacktrace, I believe the crash comes from |
@tylerjroach It is already wrapped in a try/catch |
@xaluxs Can you show me a larger code snippet that shows this? |
From the snippet that you provided above, I can't see what scope you are currently in for executing the suspending function:
However, I believe the issue you are running into is not having proper try/catches inside the scope. For example, the below code cannot catch the exception, as you cannot try/catch an exception from within a coroutine outside of its scope.
The necessary implementation is to try/catch an exception from a suspending function inside of its own scope. This example below will catch the exception you are experiencing.
|
@tylerjroach Broadly speaking, it is in the implementation to start uploading the images. 1 - Check if it is already in progress or start a new upload override suspend fun uploadPhoto(photo: S3Photo) {
try {
/** TODO Check if the photo is already uploaded or in progress. **/
val image = multiPhotoDao.fetchPhotoByPhotoId(photo.photoId) ?: return
val imageState = TransferState.getState(image.status)
val transfer = try { Amplify.Storage.getTransfer(image.transferId) } catch (e: Exception) {
printe("onProgress_X Error to get transfer imageState -> $imageState ")
C.NULL
}
printd("onProgress_X= 00000 ${transfer?.transferState} - ${jobs.containsKey(image.photoId)} status ${jobs.size} ${transfer?.error} --- ")
if (transfer != null) {
val transferState = transfer.transferState
if (transferState.isFailed()) {
removeJobAndStartNewUpload(image)
} else if (TransferState.isStarted(transferState)) {
transfer.resume()
} else {
if (jobs.containsKey(image.photoId)) {
transfer.start()
} else {
removeJobAndStartNewUpload(image)
}
}
} else {
if (imageState == TransferState.COMPLETED) {
if (photo is MultiPhotoEntity) {
onFinish.emit(Pair(photo.captureId, photo.subFormId))
}
} else {
removeJobAndStartNewUpload(image)
}
}
} catch (e: Exception) {
printd("onProgress_X= Exception ${photo.photoId} ${e.printStackTrace()}")
/** Try uploading again. **/
if (e.message?.contains(C.TRANSFER_ID_NOT_FOUND) == C.TRUE) {
val image = multiPhotoDao.fetchPhotoByPhotoId(photo.photoId) ?: return
if (image.status != TransferState.COMPLETED.name) {
removeJobAndStartNewUpload(photo)
}
}
onUploadFailed(photo, e.stackTraceToString())
}
} 2 - removeJobAndStartNewUpload protected open suspend fun removeJobAndStartNewUpload(photo: S3Photo) {
val uploadJob = jobs[photo.photoId]
uploadJob?.cancelAndJoin()
val progressJob = jobs[photo.transferId]
progressJob?.cancelAndJoin()
jobs.remove(photo.photoId)
jobs.remove(photo.transferId)
val job = scope.launch { starNewUpload(photo) }
jobs[photo.photoId] = job
} 3 - starNewUpload @OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class)
override suspend fun starNewUpload(photo: S3Photo) {
Uri.parse(photo.localURL).path?.let { File(it) }?.let { file ->
if (!file.canRead()) {
onImageNotFound(photo)
return
}
val upload = Amplify.Storage.uploadFile(buildKey(file.name), file, buildOptions())
val transferId = upload.transferId
multiPhotoDao.setTransferId(photo.photoId, transferId)
val progressJob = scope.launch {
upload.progress().collect { uploadProgressChange(photo.photoId, it) }
}
jobs[transferId] = progressJob
val s3Key = upload.result().key
uploadFinish(photo.photoId, s3Key)
jobs[photo.photoId]?.cancelAndJoin()
jobs.remove(photo.photoId)
progressJob.cancel()
jobs.remove(transferId)
} ?: run {
onImageNotFound(photo)
}
} |
@tylerjroach Ok, I think the problem may be that I am not doing it within the scope of the coroutine or I don't know when or why I remove it 👾. As soon as I can I make the change and confirm that I am leaving home. |
@tylerjroach Hi, I was barely able to confirm and if the error was due to what was mentioned, it already works correctly for me, I don't know why I missed it. try {
upload.result()
} catch (e: exception) {
//handle error
} Just one more thing, there is more detailed documentation in which scenarios resume(), start() of Amplify.Storage.getTransfer(image.transferId) would be used. For example, if a load remains in the IN_PROGRESS state |
This issue is now closed. Comments on closed issues are hard for our team to see. |
Before opening, please confirm:
Language and Async Model
Kotlin - Coroutines
Amplify Categories
Storage
Gradle script dependencies
Environment information
Please include any relevant guides or documentation you're referencing
No response
Describe the bug
This happens on phones, it is not a duplicate of the one that already exists since the other thing only happened on Wear Os
I have an application in which I load image-type files, with an approximate weight of 2 to 8 MB, the problem is that when the internet speed is very low, such as 3G or 4G or low-speed Wi-Fi, it generates HttpErrorCode(SOCKET_TIMEOUT) and close the application, I can't catch the error with try/catch
Reproduction steps (if applicable)
No response
Code Snippet
Log output
amplifyconfiguration.json
No response
GraphQL Schema
Additional information and screenshots
To replicate this you could use Charles or Proxyman
The text was updated successfully, but these errors were encountered: