build-helper-maven-plugin icon indicating copy to clipboard operation
build-helper-maven-plugin copied to clipboard

reserve_network_port no lock multiple instance builds

Open xiaoyao9184 opened this issue 6 months ago • 0 comments

When multiple Maven instances are running at the same time, for example, when using git flow finish release, CI will build branches and tags at the same time. The two executions will use the same minPortNumber and maxPortNumber configurations to find ports. At this time, there is a high probability that the same port will be found, but in the end only one instance can be listened to, and the other will fail. Is there a similar locking mechanism to ensure that multiple instances across processes obtain exclusive port usage rights, or can I only introduce a retry mechanism to run the entire Maven instance?

The following is an extreme example, where 2 out of 3 ports are found. If two Maven instances are run at the same time, one of the ports will inevitably be found by both.

<execution>
    <id>reserve-tomcat-port</id>
    <goals>
	    <goal>reserve-network-port</goal>
    </goals>
    <phase>process-resources</phase>
    <configuration>
	    <maxPortNumber>38773</maxPortNumber>
	    <minPortNumber>38771</minPortNumber>
	    <randomPort>true</randomPort>
	    <portNames>
		    <portName>random.jmx.port</portName>
		    <portName>tomcat.http.port</portName>
	    </portNames>
    </configuration>
</execution>
[INFO]
[INFO] --- build-helper-maven-plugin:3.6.0:reserve-network-port (reserve-tomcat-port) @ test-boot ---
[INFO] Port assigned 38773
[INFO] Reserved port 38773 for random.jmx.port
[INFO] Port assigned 38771
[INFO] Reserved port 38771 for tomcat.http.port
[INFO]
[INFO] --- build-helper-maven-plugin:3.6.0:reserve-network-port (reserve-tomcat-port) @ test-boot ---
[INFO] Port assigned 38772
[INFO] Reserved port 38772 for random.jmx.port
[INFO] Port assigned 38771
[INFO] Reserved port 38771 for tomcat.http.port

xiaoyao9184 avatar Aug 25 '24 10:08 xiaoyao9184