quarkus icon indicating copy to clipboard operation
quarkus copied to clipboard

No port conflict when running via jar and via dev mode at the same time

Open llowinge opened this issue 2 years ago • 7 comments

Describe the bug

When running application via jar and via dev mode at the same time, then it doesn't fail with port 8080 conflict.

Expected behavior

It should fail with port 8080 conflict.

Actual behavior

It doesn't fail with port conflict.

How to Reproduce?

Take some simple app eg. RESTEasy Classic from https://code.quarkus.io/ and perform:

  1. mvn clean package -DskipTests
  2. Run java -jar target/quarkus-app/quarkus-run.jar
  3. Open second terminal
  4. Run java -jar target/quarkus-app/quarkus-run.jar
  5. It fails with Port 8080 seems to be in use by another process. Quarkus may already be running or the port is used by another application.
  6. In second terminal run mvn compile quarkus:dev, it doesn't fail even it listens on the same 8080 port

Output of uname -a or ver

Darwin llowinge-mac 19.6.0 Darwin Kernel Version 19.6.0: Tue Jun 21 21:18:39 PDT 2022; root:xnu-6153.141.66~1/RELEASE_X86_64 x86_64

Output of java -version

openjdk version "11.0.14" 2022-01-18 LTS OpenJDK Runtime Environment Zulu11.54+23-CA (build 11.0.14+9-LTS) OpenJDK 64-Bit Server VM Zulu11.54+23-CA (build 11.0.14+9-LTS, mixed mode)

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.11.2.Final

Build tool (ie. output of mvnw --version or gradlew --version)

3.8.4

Additional information

No response

llowinge avatar Aug 08 '22 09:08 llowinge

This is by design. There is an error in the logs mentioning the issue but the application does not fail in order to allow for recovering using live-reload

geoand avatar Aug 08 '22 13:08 geoand

@geoand I don't see any error in logs

mvn compile quarkus:dev
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------< org.acme:code-with-quarkus >---------------------
[INFO] Building code-with-quarkus 1.0.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ code-with-quarkus ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO]
[INFO] --- quarkus-maven-plugin:2.11.2.Final:generate-code (default) @ code-with-quarkus ---
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ code-with-quarkus ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- quarkus-maven-plugin:2.11.2.Final:dev (default-cli) @ code-with-quarkus ---
[INFO] Invoking org.apache.maven.plugins:maven-resources-plugin:2.6:testResources) @ code-with-quarkus
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/llowinge/Downloads/code-with-quarkus 4/src/test/resources
[INFO] Invoking io.quarkus.platform:quarkus-maven-plugin:2.11.2.Final:generate-code-tests) @ code-with-quarkus
[INFO] Invoking org.apache.maven.plugins:maven-compiler-plugin:3.8.1:testCompile) @ code-with-quarkus
[INFO] Nothing to compile - all classes are up to date
Listening for transport dt_socket at address: 5005



2022-08-08 15:29:28,683 WARN  [io.net.res.dns.DnsServerAddressStreamProviders] (build-26) Can not find {} in the classpath, fallback to system defaults. This may result in incorrect DNS resolutions on MacOS.
__  ____  __  _____   ___  __ ____  ______
 --/ __ \/ / / / _ | / _ \/ //_/ / / / __/
 -/ /_/ / /_/ / __ |/ , _/ ,< / /_/ /\ \
--\___\_\____/_/ |_/_/|_/_/|_|\____/___/
2022-08-08 15:29:29,310 INFO  [io.quarkus] (Quarkus Main Thread) code-with-quarkus 1.0.0-SNAPSHOT on JVM (powered by Quarkus 2.11.2.Final) started in 1.616s. Listening on: http://localhost:8080

2022-08-08 15:29:29,311 INFO  [io.quarkus] (Quarkus Main Thread) Profile dev activated. Live Coding activated.
2022-08-08 15:29:29,312 INFO  [io.quarkus] (Quarkus Main Thread) Installed features: [cdi, resteasy, smallrye-context-propagation, vertx]
2022-08-08 15:29:36,567 INFO  [io.quarkus] (Shutdown thread) code-with-quarkus stopped in 0.021s

--


[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  13.571 s
[INFO] Finished at: 2022-08-08T15:29:37+02:00
[INFO] ------------------------------------------------------------------------

llowinge avatar Aug 08 '22 13:08 llowinge

I have this:

2022-08-08 16:06:31,057 ERROR [io.qua.run.Application] (Quarkus Main Thread) Port 8080 seems to be in use by another process. Quarkus may already be running or the port is used by another application.

2022-08-08 16:06:31,060 WARN  [io.qua.run.Application] (Quarkus Main Thread) Use 'netstat -anop | grep 8080' to identify the process occupying the port.
2022-08-08 16:06:31,060 WARN  [io.qua.run.Application] (Quarkus Main Thread) You can try to kill it with 'kill -9 <pid>'.

geoand avatar Aug 08 '22 13:08 geoand

@geoand So it must be MacOS specific problem. I've tried on Linux as well and it printed the errors you've mentioned.

Maybe related to fact that jar is listening on http://0.0.0.0:8080 and dev on http://localhost:8080.

llowinge avatar Aug 08 '22 13:08 llowinge

Understood, reopening.

@gastaldi can you try this out please?

geoand avatar Aug 08 '22 13:08 geoand

I can confirm this behavior.

Maybe related to fact that jar is listening on http://0.0.0.0:8080 and dev on http://localhost:8080.

That's right, I get the error if I run mvn compile quarkus:dev -Dquarkus.http.host=0.0.0.0 (or java -Dquarkus.http.host=localhost -jar target/quarkus-app/quarkus-run.jar)

gastaldi avatar Aug 08 '22 14:08 gastaldi

Probably related to https://github.com/quarkusio/quarkus/blob/main/extensions/vertx/runtime/src/main/java/io/quarkus/vertx/core/runtime/config/EventBusConfiguration.java#L94 (or similar option) which allows multiple sockets to be bound to the same IP/Port.

In https://stackoverflow.com/questions/14388706/how-do-so-reuseaddr-and-so-reuseport-differ is explained difference between Linux and BSD when SO_REUSEADDR is set.

llowinge avatar Aug 08 '22 14:08 llowinge