ksoichiro / gradle-web-resource-plugin

Gradle plugin to use CoffeeScript, LESS and Bower libraries without Node.js/npm.
Apache License 2.0
23 stars 5 forks source link

Bower dependencies installation is sometimes aborted #3

Closed ksoichiro closed 8 years ago

ksoichiro commented 8 years ago

Following configuration should install bower and jquery (bower's dependency), but sometimes jquery installation is aborted without raising any build errors.

webResource {
    bower {
        dependencies {
            install name: "bootstrap", version: "3.3.4"
        }
    }
}
ksoichiro commented 8 years ago

Tried a lot, but after rebooted my machine, I couldn't reproduce the problem. (Before rebooting, I saw "Too many open files in system" error in other gradle task. Is it related to number of file descriptors..?) Anyway maybe I should add some validations for this problem.

sratatata commented 8 years ago

According to this issue, there is a problem with capturing output.

I've using this for test:

try {
            status = script.execute().get()
            if (!successfullyFinished()) {
                throw new GradleException("Error occurred while processing JavaScript. exitCode: ${status?.exitCode}, cause: ${status?.cause?.message}", status?.cause)
            }
        }catch(Throwable e){
            println "Blows on: "+ scriptName
            println args;
            e.printStackTrace()
        }finally{
            env.close()
        }

Sometimes status = script.execute().get() throws exception form javascript. Then it throw runtime immidietely and never call if (!successfullyFinished()) It would be better to capture this exception and rethrow it from catch block.

Above code is just for idea. We need to think a little bit on Throwable type and getting errors from output also. However this could be good lead.

You know console is not thread safe and for sure:

status = script.execute().get()

Is not thread safe and could cause concurrency exceptions.

ksoichiro commented 8 years ago

You're right. I confirmed that if (!successfullyFinished()) is not called. It seems calling process.exit(1) in async functions in JavaScript does not exit JavaScript with error code 1. I found a workaround for this, so I'll apply it soon (though I'm not sure for the original issue).

ksoichiro commented 8 years ago

With the fix above, some errors are still not reported to callbacks in bower.js of this plugin, so I checked bower's behavior. Then I saw a weird behavior with bower 1.6.3 (bundled in this plugin) that it exits without raising error.

For example, when jquery#1.11.2 is already cached and after that I set an invalid proxy in ~/.bowerrc, following command exit with code 0.

$ bower -v   
1.6.3
$ cat <<'EOF' > ~/.bowerrc
> {
>     "proxy": "http://localhost:8080"
> }
> EOF
$ ls -l bower_components
$ bower cache list jquery
jquery=git://github.com/jquery/jquery-dist.git#1.11.2
$ bower install jquery#1.11.2
bower jquery#1.11.2         not-cached https://github.com/jquery/jquery-dist.git#1.11.2
bower jquery#1.11.2            resolve https://github.com/jquery/jquery-dist.git#1.11.2
bower jquery#1.11.2           download https://github.com/jquery/jquery-dist/archive/1.11.2.tar.gz
bower jquery#1.11.2              retry Download of https://github.com/jquery/jquery-dist/archive/1.11.2.tar.gz failed with ECONNRESET, retrying in 2.0s
bower jquery#1.11.2              retry Download of https://github.com/jquery/jquery-dist/archive/1.11.2.tar.gz failed with ECONNRESET, retrying in 2.3s
bower jquery#1.11.2              retry Download of https://github.com/jquery/jquery-dist/archive/1.11.2.tar.gz failed with ECONNRESET, retrying in 5.0s
bower jquery#1.11.2              retry Download of https://github.com/jquery/jquery-dist/archive/1.11.2.tar.gz failed with ECONNRESET, retrying in 10.8s
bower jquery#1.11.2              retry Download of https://github.com/jquery/jquery-dist/archive/1.11.2.tar.gz failed with ECONNRESET, retrying in 25.8s
bower jquery#1.11.2              retry Download of https://github.com/jquery/jquery-dist/archive/1.11.2.tar.gz failed with ECONNRESET, retrying in NaNs
$ echo $?
0

When jquery#1.11.2 is not cached, bower exits with error.

$ bower cache clean jquery
bower deleted       Cached package jquery: /Users/dev/.cache/bower/packages/8ccd8ff8cca80bc6237ebfb752ea634b/1.11.2
$ ls -l bower_components
$ bower install jquery#1.11.2
bower                            retry Request to https://bower.herokuapp.com/packages/jquery failed with ECONNRESET, retrying in 1.9s
bower                            retry Request to https://bower.herokuapp.com/packages/jquery failed with ECONNRESET, retrying in 2.3s
bower                            retry Request to https://bower.herokuapp.com/packages/jquery failed with ECONNRESET, retrying in 4.1s
bower                            retry Request to https://bower.herokuapp.com/packages/jquery failed with ECONNRESET, retrying in 12.5s
bower                            retry Request to https://bower.herokuapp.com/packages/jquery failed with ECONNRESET, retrying in 18.6s
bower                       ECONNRESET Request to https://bower.herokuapp.com/packages/jquery failed: tunneling socket could not be established, cause=connect ECONNREFUSED 127.0.0.1:8080
$ echo $?
1

Perhaps bower itself might have some issues around this.

ksoichiro commented 8 years ago

I checked the latest version of bower (1.7.6), and with this version I couldn't observe the above behavior. When bower can't download dependency via https with invalid proxy, bower tries to download with git.

$ bower install jquery#1.11.2
bower jquery#1.11.2         not-cached https://github.com/jquery/jquery-dist.git#1.11.2
bower jquery#1.11.2            resolve https://github.com/jquery/jquery-dist.git#1.11.2
bower jquery#1.11.2           download https://github.com/jquery/jquery-dist/archive/1.11.2.tar.gz
bower jquery#1.11.2              retry Download of https://github.com/jquery/jquery-dist/archive/1.11.2.tar.gz failed with ECONNRESET, retrying in 1.7s
bower jquery#1.11.2              retry Download of https://github.com/jquery/jquery-dist/archive/1.11.2.tar.gz failed with ECONNRESET, retrying in 3.5s
bower jquery#1.11.2              retry Download of https://github.com/jquery/jquery-dist/archive/1.11.2.tar.gz failed with ECONNRESET, retrying in 5.2s
bower jquery#1.11.2              retry Download of https://github.com/jquery/jquery-dist/archive/1.11.2.tar.gz failed with ECONNRESET, retrying in 11.7s
bower jquery#1.11.2              retry Download of https://github.com/jquery/jquery-dist/archive/1.11.2.tar.gz failed with ECONNRESET, retrying in 28.3s
bower jquery#1.11.2              retry Download of https://github.com/jquery/jquery-dist/archive/1.11.2.tar.gz failed with ECONNRESET, trying with git..
bower jquery#1.11.2           checkout 1.11.2
bower jquery#1.11.2           progress Receiving objects:  90% (243/269), 492.00 KiB | 97.00 KiB/s
bower jquery#1.11.2           progress Receiving objects:  96% (259/269), 588.00 KiB | 88.00 KiB/s
bower jquery#1.11.2           resolved https://github.com/jquery/jquery-dist.git#1.11.2

And after the git downloading success, I also set invalid https-proxy. Then bower immediately fails:

$ bower install jquery#1.11.2
bower jquery#1.11.2             cached https://github.com/jquery/jquery-dist.git#1.11.2
bower jquery#1.11.2           validate 1.11.2 against https://github.com/jquery/jquery-dist.git#1.11.2
bower jquery#1.11.2            ECMDERR Failed to execute "git ls-remote --tags --heads https://github.com/jquery/jquery-dist.git", exit code of #128 fatal: unable to access 'https://github.com/jquery/jquery-dist.git/': Failed to connect to localhost port 8080: Connection refused

Additional error details:
fatal: unable to access 'https://github.com/jquery/jquery-dist.git/': Failed to connect to localhost port 8080: Connection refused

The problem that bower does not report some type of errors might still exist, but v1.7.6 seems better than v1.6.3 at least about this cache/proxy handling. I should consider updating bower in this plugin.

sratatata commented 8 years ago

Thx. Sorry for late respone, I've been busy. I would try this version.

ksoichiro commented 8 years ago

No problem. I've updated bower in the plugin, but it seems this issue still exists.

ksoichiro commented 8 years ago

I've fixed this and released as v1.3.0.

The main cause is that Trireme exits event loop while installing dependencies asynchronously. I added a loop for waiting installation finish event, and this loop successfully prevented Trireme from exiting unintentionally.