Fix NullPointerException, deadlock when stopping the server (#1220)

This commit is contained in:
Steank 2022-07-08 19:31:54 +00:00 committed by GitHub
parent de5a396c15
commit 0989c220f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -97,7 +97,10 @@ public final class Server {
public void stop() {
this.stop = true;
try {
this.serverSocket.close();
if(serverSocket != null) {
this.serverSocket.close();
}
if (socketAddress instanceof UnixDomainSocketAddress unixDomainSocketAddress) {
Files.deleteIfExists(unixDomainSocketAddress.getPath());
}

View File

@ -26,7 +26,7 @@ public class ServerAddressTest {
}
@Test
public void unixAddressTest() throws IOException, InterruptedException {
public void unixAddressTest() throws IOException {
UnixDomainSocketAddress address = UnixDomainSocketAddress.of("minestom.sock");
var server = new Server(new PacketProcessor());
server.init(address);
@ -39,4 +39,10 @@ public class ServerAddressTest {
assertDoesNotThrow(server::stop);
assertFalse(Files.exists(address.getPath()), "The socket file should be deleted");
}
@Test
public void noAddressTest() throws IOException {
var server = new Server(new PacketProcessor());
assertDoesNotThrow(server::stop);
}
}