Skip to content
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

上传中,切换网络或者断网,没有失败回调 #490

Open
kelthuzad13 opened this issue Sep 21, 2022 · 6 comments
Open

上传中,切换网络或者断网,没有失败回调 #490

kelthuzad13 opened this issue Sep 21, 2022 · 6 comments

Comments

@kelthuzad13
Copy link

kelthuzad13 commented Sep 21, 2022

uploadManager 是全局单例

 private val qiniuUploadManager: UploadManager by lazy {
        UploadManager(
            Configuration.Builder()
                .resumeUploadVersion(Configuration.RESUME_UPLOAD_VERSION_V2)
                .useConcurrentResumeUpload(true)
                .concurrentTaskCount(3)
                .connectTimeout(10)
                .responseTimeout(10)
                .build()
        )
    }

使用的 sdk 是 8.4.4 版本

implementation('com.qiniu:qiniu-android-sdk:8.4.4') {
        exclude(group: 'com.squareup.okhttp3', module: 'okhttp')
    }

在 UpProgressHandler 已经有进度回调时,断开网络时(测试反馈是 Wi-Fi 切换 4g,开发场景是断开网络),连接超时没有 UpCompletionHandler 的回调。

升级到 8.5.0 之后,相同的操作步骤,会在断开网络后, com.qiniu.android.dns.dns.DohResolver 间隔 3 秒无限重试,没有失败的出口回调。

@kelthuzad13
Copy link
Author

com.qiniu.android.bigdata.client.Client 的 constructor 中设置了 builder.writeTimeout(0, TimeUnit.SECONDS);

这里是无限等待,是否要考虑下网络中断的场景?

@YangSen-qn
Copy link
Contributor

com.qiniu.android.bigdata.client.Client 的 constructor 中设置了 builder.writeTimeout(0, TimeUnit.SECONDS);

这里是无限等待,是否要考虑下网络中断的场景?

v8.* 之后,上传业务使用的不再是这个 client 。

@YangSen-qn
Copy link
Contributor

YangSen-qn commented Sep 23, 2022

@kelthuzad13
我们按照你提供的代码测试了 v8.4.4 版本:
手机型号:oppo
测试系统: Android 5.1
①上传小文件 内部采用 表单上传,在上传 20% 左右采取:

  • 断网:约 2s 会收到网络异常回调。
  • 断开 WIFi 使用移动:中间会有短暂的停顿,系统内部在切换网络链路进行重试(我们测试大约 10s ), 后续会继续上传。

②上传大文件 内部采用 分片上传,在上传 20% 左右采取:

  • 断网:约 2s 会收到网络异常回调。
  • 断开 WIFi 使用移动:中间会有短暂的停顿,系统内部在切换网络链路进行重试(我们测试大约 5s ), 后续会继续上传。

以上场景均未复现没有回调的问题,能否提供一个可复现的 demo 以及复现的步骤,我们在详细验证下?

@kelthuzad13
Copy link
Author

kelthuzad13 commented Sep 23, 2022

我们这边是基于 android 6.0 的 AOSP 自定义系统(车载),网络环境切换时会发广播 android.net.conn.NET_STATUS_CHANGE. 这个广播我看 sdk 里面好像没有监听,但是用到了 ConnectivityManager,但也没有用到 NetworkCallback.

导入 sdk 的方式是

 implementation('com.qiniu:qiniu-android-sdk:8.5.0') {
        exclude(group: 'com.squareup.okhttp3', module: 'okhttp')
 }

场景是 手动断开网络至无网。wifi 切 4g 需要专门的测试场景,有需要的话我再找测试复现后抓 log。

一些相关的 log见附件, uploadmanager 代码如下


/**
 * 上传文件相关管理
 *
 */
object UploadManager {
    private val qiniuUploadManager: UploadManager by lazy {
        UploadManager(
            Configuration.Builder()
                .resumeUploadVersion(Configuration.RESUME_UPLOAD_VERSION_V2)
                .useConcurrentResumeUpload(true)
                .concurrentTaskCount(3)
                .connectTimeout(10)
                .responseTimeout(10)
                .build()
        )
    }

    /**
     * 取消上传,设置为 true 时,
     */
    @Volatile
    var cancel = false

    fun uploadFile(
        filePath: String,
        remoteName: String,
        token: String,
        listener: UploadListener?
    ) {
        cancel = false
        qiniuUploadManager.put(
            filePath,
            remoteName,
            token,
            { key, info, response ->
                LogUtil.d(
                    "UploadManager",
                    "uploadFile",
                    "key",
                    key,
                    "info",
                    info,
                    "response",
                    response
                )
                if (info.isOK && response != null) {
                    listener?.onUploadSuccess(
                        response.optString("hash"),
                        response.optString("key")
                    )
                } else {
                    listener?.onUploadFail(response)
                }
            },
            UploadOptions(
                null,
                null,
                false,
                { key, percent ->
                    LogUtil.d(
                        "UploadManager",
                        "uploadProgress",
                        "key",
                        key,
                        "percent",
                        percent
                    )
                    listener?.onProgress(percent)
                },
                { cancel }
            )
        )
    }

    @JvmDefaultWithoutCompatibility
    interface UploadListener {
        fun onProgress(percent: Double) {}

        fun onUploadSuccess(hash: String, key: String)

        fun onUploadFail(response: JSONObject?) {}
    }

network_lost.log

@kelthuzad13
Copy link
Author

8.5.0 问题仍然存在,能再帮忙看下有什么优化方案吗?

@YangSen-qn
Copy link
Contributor

@kelthuzad13 方便说下怎么构造你们的 AOSP 环境吗?或者留个联系方式,我们具体了解下细节?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants