mirror of
https://github.com/Minestom/Minestom.git
synced 2024-09-28 06:27:27 +02:00
Fix NullPointerException, deadlock when stopping the server (#1220)
This commit is contained in:
parent
de5a396c15
commit
0989c220f6
@ -97,7 +97,10 @@ public final class Server {
|
|||||||
public void stop() {
|
public void stop() {
|
||||||
this.stop = true;
|
this.stop = true;
|
||||||
try {
|
try {
|
||||||
this.serverSocket.close();
|
if(serverSocket != null) {
|
||||||
|
this.serverSocket.close();
|
||||||
|
}
|
||||||
|
|
||||||
if (socketAddress instanceof UnixDomainSocketAddress unixDomainSocketAddress) {
|
if (socketAddress instanceof UnixDomainSocketAddress unixDomainSocketAddress) {
|
||||||
Files.deleteIfExists(unixDomainSocketAddress.getPath());
|
Files.deleteIfExists(unixDomainSocketAddress.getPath());
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ public class ServerAddressTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void unixAddressTest() throws IOException, InterruptedException {
|
public void unixAddressTest() throws IOException {
|
||||||
UnixDomainSocketAddress address = UnixDomainSocketAddress.of("minestom.sock");
|
UnixDomainSocketAddress address = UnixDomainSocketAddress.of("minestom.sock");
|
||||||
var server = new Server(new PacketProcessor());
|
var server = new Server(new PacketProcessor());
|
||||||
server.init(address);
|
server.init(address);
|
||||||
@ -39,4 +39,10 @@ public class ServerAddressTest {
|
|||||||
assertDoesNotThrow(server::stop);
|
assertDoesNotThrow(server::stop);
|
||||||
assertFalse(Files.exists(address.getPath()), "The socket file should be deleted");
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user