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

Download error The current offset on block-info isn't update correct, 1648345 != 11469669 on 0 V1.0.7版本还是遇到这个问题,导致任务中断,进度跳变 #415

Open
daiqiquan opened this issue Aug 20, 2020 · 14 comments

Comments

@daiqiquan
Copy link

OkDownload Version

v1.0.2-SNAPSHOT

Problem Describe

I occur some problem, I also search on issues and wiki, I even checked the source code, but it can't help, so my real problem is:...

Log

There is the whole log from LogCat when I occur the problem(I know we can use this tool to let log more readable):

@noneorone
Copy link

android10版本会遇到网络不稳定时,下载异常中断

@mradzinski
Copy link

@oneornone That's not true. I'm on a 100mb/s very stable WiFi and I get this on every download where setConnectionCount is more than 1. It's a library issue, not an Android one.

@wys619
Copy link

wys619 commented Sep 9, 2020

the same problem happen on my device: pixel3 running Android 11 . thanks!

slowlow79464 added a commit to slowlow79464/okdownload that referenced this issue Sep 29, 2020
@slowlow79464
Copy link

slowlow79464 commented Sep 29, 2020

@daiqiquan I face the same problem, and debug it for days. Finnally I found the cause and send the pull request. Hope helps.

@hasansidd
Copy link

@Jacksgong, will this fix be pushed to maven any time soon?

Adizbek added a commit to Adizbek/okdownload that referenced this issue Oct 22, 2020
@Jiang00
Copy link

Jiang00 commented Nov 20, 2020

@slowlow79464 It has been modified in your way, but this error will still be reported

@kutukoff
Copy link

kutukoff commented Jan 1, 2021

Hi, there!

I use temp fix before author can't approve merge request #425

@slowlow79464 & @mradzinski Thanks for help =)

========================

1. Add Override fixed classes (I created same package name, its doesn't matter)

CustomProcessFileStrategy.class

package com.liulishuo.okdownload.core.file;

import androidx.annotation.NonNull;

import com.liulishuo.okdownload.DownloadTask;
import com.liulishuo.okdownload.core.breakpoint.BreakpointInfo;
import com.liulishuo.okdownload.core.breakpoint.DownloadStore;

public class CustomProcessFileStrategy extends ProcessFileStrategy {

    @Override
    @NonNull
    public MultiPointOutputStream createProcessStream(@NonNull DownloadTask task,
                                                      @NonNull BreakpointInfo info,
                                                      @NonNull DownloadStore store) {
        return new CustomMultiPointOutputStream(task, info, store);
    }
}

and CustomMultiPointOutputStream.class

package com.liulishuo.okdownload.core.file;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.liulishuo.okdownload.DownloadTask;
import com.liulishuo.okdownload.core.Util;
import com.liulishuo.okdownload.core.breakpoint.BreakpointInfo;
import com.liulishuo.okdownload.core.breakpoint.DownloadStore;

import java.io.IOException;

public class CustomMultiPointOutputStream extends MultiPointOutputStream {
    private static final String TAG = "CustomMultiPointOutputStream";
    private final DownloadTask task;

    CustomMultiPointOutputStream(@NonNull final DownloadTask task,
                                 @NonNull BreakpointInfo info,
                                 @NonNull DownloadStore store,
                                 @Nullable Runnable syncRunnable) {
        super(task, info, store, syncRunnable);
        this.task = task;
    }

    public CustomMultiPointOutputStream(@NonNull DownloadTask task,
                                        @NonNull BreakpointInfo info,
                                        @NonNull DownloadStore store) {
        this(task, info, store, null);
    }

    @Override
    synchronized void close(int blockIndex) throws IOException {
        final DownloadOutputStream outputStream = outputStreamMap.get(blockIndex);
        if (outputStream != null) {
            outputStream.close();
            synchronized (noSyncLengthMap) {
                // make sure the length of noSyncLengthMap is equal to outputStreamMap
                outputStreamMap.remove(blockIndex);
                noSyncLengthMap.remove(blockIndex);
            }
            Util.d(TAG, "OutputStream close task[" + task.getId() + "] block[" + blockIndex + "]");
        }
    }
}

2. Add in you Application.onCreate() class:

OkDownload.setSingletonInstance(
                new OkDownload.Builder(this)
                        .processFileStrategy(new CustomProcessFileStrategy())
                        .build()
        );

Enjoy!

@MZCretin
Copy link

这个解决方案好像并不能完全解决 还是有概率出现问题

@svenjung
Copy link

关闭多线程下载,,,

@chenlin139
Copy link

Hi, there!

I use temp fix before author can't approve merge request #425

@slowlow79464 & @mradzinski Thanks for help =)

========================

1. Add Override fixed classes (I created same package name, its doesn't matter)

CustomProcessFileStrategy.class

package com.liulishuo.okdownload.core.file;

import androidx.annotation.NonNull;

import com.liulishuo.okdownload.DownloadTask;
import com.liulishuo.okdownload.core.breakpoint.BreakpointInfo;
import com.liulishuo.okdownload.core.breakpoint.DownloadStore;

public class CustomProcessFileStrategy extends ProcessFileStrategy {

    @Override
    @NonNull
    public MultiPointOutputStream createProcessStream(@NonNull DownloadTask task,
                                                      @NonNull BreakpointInfo info,
                                                      @NonNull DownloadStore store) {
        return new CustomMultiPointOutputStream(task, info, store);
    }
}

and CustomMultiPointOutputStream.class

package com.liulishuo.okdownload.core.file;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.liulishuo.okdownload.DownloadTask;
import com.liulishuo.okdownload.core.Util;
import com.liulishuo.okdownload.core.breakpoint.BreakpointInfo;
import com.liulishuo.okdownload.core.breakpoint.DownloadStore;

import java.io.IOException;

public class CustomMultiPointOutputStream extends MultiPointOutputStream {
    private static final String TAG = "CustomMultiPointOutputStream";
    private final DownloadTask task;

    CustomMultiPointOutputStream(@NonNull final DownloadTask task,
                                 @NonNull BreakpointInfo info,
                                 @NonNull DownloadStore store,
                                 @Nullable Runnable syncRunnable) {
        super(task, info, store, syncRunnable);
        this.task = task;
    }

    public CustomMultiPointOutputStream(@NonNull DownloadTask task,
                                        @NonNull BreakpointInfo info,
                                        @NonNull DownloadStore store) {
        this(task, info, store, null);
    }

    @Override
    synchronized void close(int blockIndex) throws IOException {
        final DownloadOutputStream outputStream = outputStreamMap.get(blockIndex);
        if (outputStream != null) {
            outputStream.close();
            synchronized (noSyncLengthMap) {
                // make sure the length of noSyncLengthMap is equal to outputStreamMap
                outputStreamMap.remove(blockIndex);
                noSyncLengthMap.remove(blockIndex);
            }
            Util.d(TAG, "OutputStream close task[" + task.getId() + "] block[" + blockIndex + "]");
        }
    }
}

2. Add in you Application.onCreate() class:

OkDownload.setSingletonInstance(
                new OkDownload.Builder(this)
                        .processFileStrategy(new CustomProcessFileStrategy())
                        .build()
        );

Enjoy!

MultiPointOutputStream 中的close方法不是public,怎么复写?这个问题还有什么解决方法吗

@mysiga
Copy link

mysiga commented Mar 26, 2022

设置单线程下载已解决
setConnectionCount(1)

@SeaWaterBlue
Copy link

设置单线程下载已解决 setConnectionCount(1)

it work

zhangchuanchuan pushed a commit to zhangchuanchuan/okdownload that referenced this issue Jul 7, 2022
@nannan111
Copy link

我策底解决了,哈哈哈

@Cake9302
Copy link

@nannan111 请教一下解决方法

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