[ https://issues.apache.org/jira/browse/CB-2787?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13683338#comment-13683338 ]
Gregor Gabriel edited comment on CB-2787 at 6/14/13 1:31 PM: ------------------------------------------------------------- As I really had to solve this problem for my app i digged in this process. I didnot want to change the cordova core code, as this would produce additional work, when I update the cordova version on my app. So I looked out for a Downloder plugin. I used this plugin with phonegap 1.2. The plugin was not up to date, as its functionality now is part of cordova core. It was not really difficult to port the plugin to cordova 2.7 . For this purpose ich checked on https://github.com/phonegap/phonegap-plugins/tree/master/Android which plugis where updated lately by _macdonst_ and did the same for the Downloader plugin. When the plugin worked I got the same problems as with cordova core. Only omitting the OutputStream in my test cases delivered the same problems. Then I only omitted the InputStream and the Problem was not there. So the Problem is the InputStream delivered from the http connection. You can close this stream how often you want, there seem to be open connections left? I'm not totally sure, but this could be a framework problem. As I really needed a solution I changed the plugin JS-file tht way, that files are loaded by JavaScript. So the plugin code only needs to write that files to the device. This was not so easy, as most files were binary, and standard JavaScript does not support to much functions to handle binary Strings. I add my solution to the next comment was (Author: ggabriel): As I really had to solve this problem for my app i digged in this process. I didnot want to change the cordova core code, as this would produce additional work, when I update the cordova version on my app. So I looked out for a Downloder plugin. I used this plugin with phonegap 1.2. The plugin was not up to date, as its functionality now is part of cordova core. Itm was not really difficult to port the plugin to cordova 2.7 . For this purpose ich checked on https://github.com/phonegap/phonegap-plugins/tree/master/Android which plugis where updated lately by _macdonst_ and did the same for the Downloader plugin. When the plugin worked I got the same problems as with cordova core. Only omitting the OutputStream in my test cases delivered the same problems. Then I only omitted the InputStream and the Problem was not there. So the Problem is the InputStream delivered from the http connection. You can close this stream how often you want, there seem to be open connections left? I'm not totally sure, but this could be a framework problem. As I really needed a solution I changed the plugin JS-file tht way, that files are loaded by JavaScript. So the plugin code only needs to write that files to the device. This was not so easy, as most files were binary, and standard JavaScript does not support to much functions to handle binary Strings. I add my solution to the next comment > PhoneGap FileTransfer.Download more than 300 files > -------------------------------------------------- > > Key: CB-2787 > URL: https://issues.apache.org/jira/browse/CB-2787 > Project: Apache Cordova > Issue Type: Bug > Components: Android > Affects Versions: 2.5.0 > Reporter: Cho > Assignee: Ian Clelland > > I had tried to download more than 300 files and then it hit error after that. > Seems like some IO Connection was not properly closed. I wrote a small code > to test it out. > Any idea? How to file a report or get a source of phonegap to check the real > cause? > {code} > var counter = 500; > function DownloadFile() { > if (counter == 0) { > DownloadComplete(); > return; > } > var ft = new FileTransfer(); > var downloadUrl = "<source>"; > var dlPath = "<target>" > ft.download(downloadUrl, dlPath, function(entry) { > counter--; > UpdateProgress(); > DownloadFile(); > }, function(error) { > DownloadFailed(); > }, true); > } > {code} > note: <target> and <source> is alright because it was it failed when the > counter goes until 300+. > {code} > 03-14 08:35:09.706: E/FileTransfer(24867): > {"target":"<target>","source":"<source>","http_status":200,"code":1} > 03-14 08:35:09.706: E/FileTransfer(24867): java.io.FileNotFoundException: > <source>: open failed: EMFILE (Too many open files) > 03-14 08:35:09.706: E/FileTransfer(24867): at > libcore.io.IoBridge.open(IoBridge.java:416) > 03-14 08:35:09.706: E/FileTransfer(24867): at > java.io.FileOutputStream.<init>(FileOutputStream.java:88) > 03-14 08:35:09.706: E/FileTransfer(24867): at > java.io.FileOutputStream.<init>(FileOutputStream.java:73) > 03-14 08:35:09.706: E/FileTransfer(24867): at > org.apache.cordova.FileTransfer$4.run(FileTransfer.java:685) > 03-14 08:35:09.706: E/FileTransfer(24867): at > java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076) > 03-14 08:35:09.706: E/FileTransfer(24867): at > java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569) > 03-14 08:35:09.706: E/FileTransfer(24867): at > java.lang.Thread.run(Thread.java:856) > 03-14 08:35:09.706: E/FileTransfer(24867): Caused by: > libcore.io.ErrnoException: open failed: EMFILE (Too many open files) > 03-14 08:35:09.706: E/FileTransfer(24867): at > libcore.io.Posix.open(Native Method) > 03-14 08:35:09.706: E/FileTransfer(24867): at > libcore.io.BlockGuardOs.open(BlockGuardOs.java:110) > 03-14 08:35:09.706: E/FileTransfer(24867): at > libcore.io.IoBridge.open(IoBridge.java:400) > 03-14 08:35:09.706: E/FileTransfer(24867): ... 6 more > {code} -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators For more information on JIRA, see: http://www.atlassian.com/software/jira