Giter Club home page Giter Club logo

Comments (7)

hnvn avatar hnvn commented on July 17, 2024

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.

cbenhagen avatar cbenhagen commented on July 17, 2024

Sorry I forgot to mention that I only tried this on iOS so far. This is where the bug occurs.

from flutter_downloader.

hnvn avatar hnvn commented on July 17, 2024

Is there any log for this case?

from flutter_downloader.

cbenhagen avatar cbenhagen commented on July 17, 2024
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.

hnvn avatar hnvn commented on July 17, 2024

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.

hnvn avatar hnvn commented on July 17, 2024

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.

cbenhagen avatar cbenhagen commented on July 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.