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

gretty 3.0.2 java.net.ConnectException: Connection refused #147

Closed
acestars opened this issue Mar 30, 2020 · 8 comments
Closed

gretty 3.0.2 java.net.ConnectException: Connection refused #147

acestars opened this issue Mar 30, 2020 · 8 comments

Comments

@acestars
Copy link

acestars commented Mar 30, 2020

I have already tried version 3.0.2 but there's error about connection refused. is there any new config?
Edit1: I am using gradle 6.3-rc1
Edit2: I already tried gradle 6.3 but still error

Caused by: java.net.ConnectException: Connection refused: connect
        at org.akhikhl.gretty.ServiceProtocol$Writer.write(ServiceProtocol.groovy:76)
        at org.akhikhl.gretty.ServiceProtocol$Writer$write.call(Unknown Source)
        at org.akhikhl.gretty.LauncherBase$_beforeLaunch_closure2.doCall(LauncherBase.groovy:71)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at org.akhikhl.gretty.LauncherBase.beforeLaunch(LauncherBase.groovy:69)
        at org.akhikhl.gretty.DefaultLauncher.super$2$beforeLaunch(DefaultLauncher.groovy)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at org.akhikhl.gretty.DefaultLauncher.beforeLaunch(DefaultLauncher.groovy:58)
        at org.akhikhl.gretty.LauncherBase.launch(LauncherBase.groovy:155)
        at org.akhikhl.gretty.Launcher$launch.call(Unknown Source)
        at org.akhikhl.gretty.StartBaseTask.action(StartBaseTask.groovy:79)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:104)
@pmarchwiak
Copy link

I'm seeing something similar, when using jetty9 as the container:

Execution failed for task ':web-service:appRun'.
> java.net.BindException: Can't assign requested address (Bind failed)

Downgrading to org.gretty:gretty:3.0.1 fixes it.

@javabrett
Copy link
Member

@f4lco any thoughts - if not obvious we can revert #139 and release without until we can resolve.

@ghost
Copy link

ghost commented Apr 2, 2020

@pmarchwiak @acestars Is it possible for you to provide a reproducing sample project? Otherwise, do you have some more details about your setup? Do you use grettys' random port feature?

Edit: Ok, it really seems to be related to gradle 6.x. The integration test "testJettyRandomPorts" fails with the above error when using gradle 6.3, but works with the packaged gradle wrapper which is 5.6.4. Conclusion was wrong. See comment below for a reproducing test case.

@f4lco
Copy link
Collaborator

f4lco commented Apr 2, 2020

I did some analysis and I think Gretty now lacks error handling when treating gretty_ports.properties. The ports are persisted in that file, and Gretty intially reads it to check if there is a server already running. In case there is no server, Gretty should not error out.

@omikron-tvr @acestars can you please also check if your test succeeds using a clean build? Or, is indeed only reproducible with that properties file in the build directory?
@javabrett If I'm on the right track, it should be possible to ship a fix in the next couple of days.

@ghost
Copy link

ghost commented Apr 2, 2020

@f4lco My conclusion regarding the gradle version was wrong. My reproducing case looks like this:

cd integrationTests/testJettyRandomPorts
gradle integrationTest
# abort with <C-c> when the app has started
gradle appRun

This fails irregardless of the exact gradle version. Without gradle integrationTest the task gradle appRun succeeds on a clean build.

rm build/gretty_ports.properties fixes appRun again as you've predicted.

@acestars
Copy link
Author

acestars commented Apr 2, 2020

Confirmed after i deleted gretty_ports.properties i can do appRun.

@pmarchwiak
Copy link

pmarchwiak commented Apr 2, 2020

I can reproduce using one of the integration test apps in this repo, helloJersey:

me@mbp:helloJersey$ git checkout v3.0.2
me@mbp:helloJersey$ gradle appRun

> Configure project :farmSecure:MyWebApp
Excluding farmSecure tests from Jetty 9.3/9.4, see https://github.com/gretty-gradle-plugin/gretty/issues/67 .
Excluding farmSecure tests from Jetty 9.3/9.4, see https://github.com/gretty-gradle-plugin/gretty/issues/67 .

> Task :helloJersey:appRun FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':helloJersey:appRun'.
> java.net.BindException: Can't assign requested address (Bind failed)

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 43s
4 actionable tasks: 4 executed
me@mbp:helloJersey$ gradle --version

------------------------------------------------------------
Gradle 5.4.1
------------------------------------------------------------

Build time:   2019-04-26 08:14:42 UTC
Revision:     261d171646b36a6a28d5a19a69676cd098a4c19d

Kotlin:       1.3.21
Groovy:       2.5.4
Ant:          Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM:          1.8.0_192 (Oracle Corporation 25.192-b12)
OS:           Mac OS X 10.13.6 x86_64

That same command works fine when using 3.0.1.

As far as I know, the app where I originally observed this is not using gretty_ports.properties. The gretty parts of its build.gradle look something like this:

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'org.gretty:gretty:+'
    }
}

apply plugin: 'org.gretty'

gretty {
    extraResourceBase "webapp"
    extraResourceBase "internal"

    httpPort = 9100
    host = 'localhost' 
    contextPath = "/app"
    fastReload = true
    jvmArgs = [
        "-Dlog4j.configuration=${projectDir.toString()}/dev.logging.lcf"
    ]
    debugSuspend = true
    jacocoEnabled false
    servletContainer = 'jetty9.4'
}

f4lco added a commit to f4lco/gretty that referenced this issue Apr 4, 2020
…ugin#147)

Because gretty-gradle-plugin#138 removed adequate error handling, the check for
already used ports was broken and caused Gretty to fail in
case the 'gretty_ports.properties' file was present.

I think the check is now obsolete because gretty-gradle-plugin#138 removed the
ability to manually specify fixed service and status ports
for Gretty. As a result, Gretty's ports will never clash
from one Gretty invocation to the next.

If the check was restored, it would only check if the
previous Gretty invocation had already terminated.

If one of the *servlet container ports* clashed, I deem
the current behavior (BindException) sufficient.
f4lco added a commit to f4lco/gretty that referenced this issue Apr 4, 2020
…ugin#147)

Because gretty-gradle-plugin#138 removed adequate error handling, the check for
already used ports was broken and caused Gretty to fail in
case the 'gretty_ports.properties' file was present.

I think the check is now obsolete because gretty-gradle-plugin#138 removed the
ability to manually specify fixed service and status ports
for Gretty. As a result, Gretty's ports will never clash
from one Gretty invocation to the next.

If the check was restored, it would only check if the
previous Gretty invocation had already terminated.

If one of the *servlet container ports* clashed, I deem
the current behavior (BindException) sufficient.
f4lco added a commit to f4lco/gretty that referenced this issue Apr 13, 2020
…ugin#147)

Because gretty-gradle-plugin#138 removed adequate error handling, the check for
already used ports was broken and caused Gretty to fail in
case the 'gretty_ports.properties' file was present.

I think the check is now obsolete because gretty-gradle-plugin#138 removed the
ability to manually specify fixed service and status ports
for Gretty. As a result, Gretty's ports will never clash
from one Gretty invocation to the next.

If the check was restored, it would only check if the
previous Gretty invocation had already terminated.

If one of the *servlet container ports* clashed, I deem
the current behavior (BindException) sufficient.
javabrett added a commit that referenced this issue May 7, 2020
Remove malformed check for already used ports (fixes #147)
@DALDEI
Copy link

DALDEI commented Oct 4, 2020

I am getting the same exception in 3.0.3
running strace on the built product "run.sh" I can see a bind() system call for IPV6 address ::ffff:

[pid 3679] bind(41, {sa_family=AF_INET6, sin6_port=htons(0), inet_pton(AF_INET6, "::ffff:10.10.0.58", &sin6_addr), sin6_flowinfo=htonl(0), sin6_scope_id=0}, 28) = -1 EADDRNOTAVAIL (Cannot assign requested address)
No idea where 10.10.0.58 is coming from, its not a valid IP for any host on my net

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

5 participants