Skip to content

Commit 98b7a7d

Browse files
Handle Netty native exception to detect port in use
1 parent d60602a commit 98b7a7d

File tree

1 file changed

+7
-0
lines changed
  • spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/netty

1 file changed

+7
-0
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/NettyWebServer.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ public class NettyWebServer implements WebServer {
6464
*/
6565
private static final int ERROR_NO_EACCES = -13;
6666

67+
private static final int ERROR_ADDR_IN_USE = -98;
68+
6769
private static final Predicate<HttpServerRequest> ALWAYS = (request) -> true;
6870

6971
private static final Log logger = LogFactory.getLog(NettyWebServer.class);
@@ -120,6 +122,11 @@ public void start() throws WebServerException {
120122
PortInUseException.throwIfPortBindingException(bindException, bindException::localPort);
121123
}
122124
});
125+
PortInUseException.ifCausedBy(ex, NativeIoException.class, (nativeIoException) -> {
126+
if (nativeIoException.expectedErr() == ERROR_ADDR_IN_USE) {
127+
throw new PortInUseException(-1, ex);
128+
}
129+
});
123130
throw new WebServerException("Unable to start Netty", ex);
124131
}
125132
if (this.disposableServer != null) {

0 commit comments

Comments
 (0)