Comments (7)
I think this case only happens on the Android side because I already queued all write to DB actions on iOS. My main idea is: lock for write and allow read always. By the way, I forgot running a transaction when I insert a new task into DB. That would account for this bug.
from flutter_downloader.
Sorry I forgot to mention that I only tried this on iOS so far. This is where the bug occurs.
from flutter_downloader.
Is there any log for this case?
from flutter_downloader.
methodCallHandler: enqueue
execute query: INSERT INTO task (task_id,url,status,progress,file_name,saved_dir,headers,resumable,show_notification,open_file_from_notification,time_created) VALUES ("com.example.test.download.background.1536665611.774887.14","https://example.com/A001C015_180901_A4R4-thumb.jpg?mtime=1536384218.54",1,0,"A001C015_180901_A4R4-thumb.jpg","/Users/ben/Library/Developer/CoreSimulator/Devices/2370C450-CC60-41A5-912A-E0E583C20889/data/Containers/Data/Application/8800C18D-EAFB-4670-B856-A5E9EF543B36/Documents","{authorization: Basic aabbcc=}",0,0,0,1536665630531)
open DB successfully
Query was executed successfully. Affected rows = 1
methodCallHandler: enqueue
execute query: INSERT INTO task (task_id,url,status,progress,file_name,saved_dir,headers,resumable,show_notification,open_file_from_notification,time_created) VALUES ("com.example.test.download.background.1536665611.774887.15","https://example.com/A001C016_180901_A4R4-thumb.jpg?mtime=1536384218.57",1,0,"A001C016_180901_A4R4-thumb.jpg","/Users/ben/Library/Developer/CoreSimulator/Devices/2370C450-CC60-41A5-912A-E0E583C20889/data/Containers/Data/Application/8800C18D-EAFB-4670-B856-A5E9EF543B36/Documents","{authorization: Basic aabbcc=}",0,0,0,1536665630542)
open DB successfully
Query was executed successfully. Affected rows = 1
methodCallHandler: enqueue
execute query: INSERT INTO task (task_id,url,status,progress,file_name,saved_dir,headers,resumable,show_notification,open_file_from_notification,time_created) VALUES ("com.example.test.download.background.1536665611.774887.16","https://example.com/A001C017_180901_A4R4-thumb.jpg?mtime=1536384218.59",1,0,"A001C017_180901_A4R4-thumb.jpg","/Users/ben/Library/Developer/CoreSimulator/Devices/2370C450-CC60-41A5-912A-E0E583C20889/data/Containers/Data/Application/8800C18D-EAFB-4670-B856-A5E9EF543B36/Documents","{authorization: Basic aabbcc=}",0,0,0,1536665630550)
open DB successfully
Query was executed successfully. Affected rows = 1
methodCallHandler: enqueue
execute query: INSERT INTO task (task_id,url,status,progress,file_name,saved_dir,headers,resumable,show_notification,open_file_from_notification,time_created) VALUES ("com.example.test.download.background.1536665611.774887.17","https://example.com/A001C018_180901_A4R4-thumb.jpg?mtime=1536384218.61",1,0,"A001C018_180901_A4R4-thumb.jpg","/Users/ben/Library/Developer/CoreSimulator/Devices/2370C450-CC60-41A5-912A-E0E583C20889/data/Containers/Data/Application/8800C18D-EAFB-4670-B856-A5E9EF543B36/Documents","{authorization: Basic aabbcc=}",0,0,0,1536665630560)
execute query: SELECT * FROM task WHERE task_id = "com.example.test.download.background.1536665611.774887.1" ORDER BY id DESC LIMIT 1
open DB successfully
open DB successfully
Load task successfully
Query was executed successfully. Affected rows = 1
methodCallHandler: enqueue
execute query: UPDATE task SET status=3, progress=100 WHERE task_id="com.example.test.download.background.1536665611.774887.1"
open DB successfully
Query was executed successfully. Affected rows = 1
execute query: INSERT INTO task (task_id,url,status,progress,file_name,saved_dir,headers,resumable,show_notification,open_file_from_notification,time_created) VALUES ("com.example.test.download.background.1536665611.774887.18","https://example.com/A001C019_180901_A4R4-thumb.jpg?mtime=1536384218.72",1,0,"A001C019_180901_A4R4-thumb.jpg","/Users/ben/Library/Developer/CoreSimulator/Devices/2370C450-CC60-41A5-912A-E0E583C20889/data/Containers/Data/Application/8800C18D-EAFB-4670-B856-A5E9EF543B36/Documents","{authorization: Basic aabbcc=}",0,0,0,1536665630572)
execute query: SELECT * FROM task WHERE task_id = "com.example.test.download.background.1536665611.774887.2" ORDER BY id DESC LIMIT 1
open DB successfully
open DB successfully
database is locked
Load task successfully
Query was executed successfully. Affected rows = 1
methodCallHandler: enqueue
Lost connection to device.
*** First throw call stack:
(
0 CoreFoundation 0x0000000109dbb7f6 __exceptionPreprocess + 294
1 libobjc.A.dylib 0x0000000108f35035 objc_exception_throw + 48
2 CoreFoundation 0x0000000109dbb675 +[NSException raise:format:] + 197
3 Foundation 0x00000001089f6422 -[NSURL(NSURL) initFileURLWithPath:] + 127
4 Foundation 0x00000001089f6c8e +[NSURL(NSURL) fileURLWithPath:] + 45
5 Runner 0x0000000106f48ff7 -[FlutterDownloaderPlugin URLSession:downloadTask:didFinishDownloadingToURL:] + 503
6 CFNetwork 0x000000010ebcf5f8 __82-[NSURLSession delegate_downloadTask:didFinishDownloadingToURL:completionHandler:]_block_invoke + 38
7 Foundation 0x00000001089a32b7 __NS<…>
from flutter_downloader.
That would be the problem of multiple threads. Two threads access to DB at the moment and as far as the logs run, the later action was failed by DB locked then it returns an empty object, the saved file path can't be loaded, so application crashed because the function [NSURL initFileURLWithPath:] doesn't accept a nil value. That's the case I read from your logs.
Multiple threads in objective-c is quite dark for me. I think I should keep the information of running task in memory instead of DB, so I can get rid of loading tasks from DB too frequently and prevent this matter.
from flutter_downloader.
By the way, I am quite busy during the week. There can be time at the weekend. So I am willing if you can contribute to this repository.
from flutter_downloader.
I tried implementing a retry loop but it seemed quite ugly and didn't fully work. But I'd give it another shot. Objc is pretty new for me though. We could also have the DB handler in one thread and give it the data through a queue.
from flutter_downloader.
Related Issues (20)
- filename issues (spaces, dots and non English letters) HOT 1
- Download not starting HOT 5
- Can not open file from notification after adding manifest code for open file HOT 1
- IllegalArgumentException from ItentUtils.buildIntent in downloadFile method HOT 2
- FlutterDownloaderDatabase.bundle: No such file or directory HOT 1
- iOS. Incorrect filename in latest download task HOT 10
- My app crashed when adding await FlutterDownloader.initialize HOT 2
- iOS. Download status is 100, but file not downloaded
- Download Task progress is shown 100 immediately. HOT 1
- I encounter failure while downloading some files, although it succeeds in downloading other files HOT 2
- How to downloading with encrypt file HOT 1
- problem open loaded task HOT 15
- Getting Error in iOS device HOT 3
- Downloader works for devices of android 13 but not working specifically for Specifically in my device Oppo F21 HOT 1
- Deleting file and download again the same file not working
- Nullpointer exception on httpconn.contentType in DownloadWorker.kt if contentType is not provided by the server. HOT 5
- httpConn.contentType must not be null error when download file HOT 1
- Flutter Download CallBack Not Working At first time HOT 5
- File Download Not working in the example project
- Flutter downloader is not working in Android (Permission denied) HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flutter_downloader.