timvisee / lazymc

💤 Put your Minecraft server to rest when idle.
GNU General Public License v3.0
552 stars 14 forks source link

Server Crashing not gracefully stopping #26

Closed VindicoRory closed 1 year ago

VindicoRory commented 2 years ago

I am running multiple servers on Ubuntu 22.04 and every single one (from 1.12.2 -> 1.19) seems to crash with error code 143, rather than gracefully shutting down. I am worried that this is going to cause data loss, and it cant be good for the saves. I have also enabled RCON to see if that resolves any issues but it seems to be the exact same. The error is shown below:


WARN  lazymc          > Server process stopped with error code (exit status: 143)
INFO  lazymc::monitor > Server is now sleeping```
timvisee commented 2 years ago

The Minecraft server itself crashes, lazymc only forwards the error.

Does the server itself run fine without using lazymc?

Milkysunshine commented 1 year ago

I was having the same issue here: #20 In my case, the server runs fine without lazymc. What I've done in the meantime, since I'm running everything in a proxmox container, I scheduled the container to shutdown at night, and restart in the morning. A couple simple cron commands made that possible. That said, I would still like to find a working option like lazymc. The idle cpu usage raises power consumption in my Dell R630 server by around 10W. Electricity is expensive here, and it isn't fun wasting money on something just sitting idle with no players connected.

obj-obj commented 1 year ago

My server shuts down normally but still has that exact same exit status, maybe the server changes the exit status if there are any warnings or something?

marissa999 commented 1 year ago

I also have the same issue. I run it in a Proxmox Container to, with Arch Linux as the OS, and I use lazymc-v0.2.9-linux-x64-static from the release page. I also use PapeMC, paper-1.19.3-404.jar to be exact, with no plugins. The command I use to start the server is command = "java -Xmx2048m -Xms512m -jar paper-1.19.3-404.jar" Running the server without lazymc has no issues, executing java -Xmx2048m -Xms512m -jar paper-1.19.3-404.jar && echo OK || echo Failed in my shell does print "OK" once the server was stopped through ctrl + c (sigint).

https://github.com/timvisee/lazymc/blob/master/docs/command-bash.md#use-bash-script-to-start-server This indicates that lazymc sends a sigterm. I wonder if that is relevant :thinking:

sh-5.1# java -version
openjdk version "19.0.1" 2022-10-18
OpenJDK Runtime Environment (build 19.0.1+10)
OpenJDK 64-Bit Server VM (build 19.0.1+10, mixed mode)
sh-5.1# 

Full logs after I disconnected:

Feb 17 19:18:19 minecraft lazymc-v0.2.9-linux-x64-static[1765]: [19:18:19 INFO]: marissaChan lost connection: Disconnected
Feb 17 19:18:19 minecraft lazymc-v0.2.9-linux-x64-static[1765]: [19:18:19 INFO]: marissaChan left the game
Feb 17 19:18:29 minecraft lazymc-v0.2.9-linux-x64-static[1505]:  INFO  lazymc::montior > Server has been idle, sleeping...
Feb 17 19:18:29 minecraft lazymc-v0.2.9-linux-x64-static[1765]: [19:18:29 INFO]: Stopping server
Feb 17 19:18:29 minecraft lazymc-v0.2.9-linux-x64-static[1765]: [19:18:29 INFO]: Saving players
Feb 17 19:18:29 minecraft lazymc-v0.2.9-linux-x64-static[1765]: [19:18:29 INFO]: Saving worlds
Feb 17 19:18:29 minecraft lazymc-v0.2.9-linux-x64-static[1765]: [19:18:29 INFO]: Saving chunks for level 'ServerLevel[world]'/minecraft:overworld
Feb 17 19:18:29 minecraft lazymc-v0.2.9-linux-x64-static[1765]: [19:18:29 INFO]: [ChunkHolderManager] Waiting 60s for chunk system to halt for world 'world'
Feb 17 19:18:29 minecraft lazymc-v0.2.9-linux-x64-static[1765]: [19:18:29 INFO]: [ChunkHolderManager] Halted chunk system for world 'world'
Feb 17 19:18:29 minecraft lazymc-v0.2.9-linux-x64-static[1765]: [19:18:29 INFO]: [ChunkHolderManager] Saving all chunkholders for world 'world'
Feb 17 19:18:30 minecraft lazymc-v0.2.9-linux-x64-static[1765]: [19:18:30 INFO]: [ChunkHolderManager] Saved 853 block chunks, 853 entity chunks, 0 poi chunks in world 'world' in 0.95s
Feb 17 19:18:30 minecraft lazymc-v0.2.9-linux-x64-static[1765]: [19:18:30 INFO]: ThreadedAnvilChunkStorage (world): All chunks are saved
Feb 17 19:18:30 minecraft lazymc-v0.2.9-linux-x64-static[1765]: [19:18:30 INFO]: Saving chunks for level 'ServerLevel[world_nether]'/minecraft:the_nether
Feb 17 19:18:30 minecraft lazymc-v0.2.9-linux-x64-static[1765]: [19:18:30 INFO]: [ChunkHolderManager] Waiting 60s for chunk system to halt for world 'world_nether'
Feb 17 19:18:30 minecraft lazymc-v0.2.9-linux-x64-static[1765]: [19:18:30 INFO]: [ChunkHolderManager] Halted chunk system for world 'world_nether'
Feb 17 19:18:30 minecraft lazymc-v0.2.9-linux-x64-static[1765]: [19:18:30 INFO]: [ChunkHolderManager] Saving all chunkholders for world 'world_nether'
Feb 17 19:18:31 minecraft lazymc-v0.2.9-linux-x64-static[1765]: [19:18:31 INFO]: [ChunkHolderManager] Saved 529 block chunks, 529 entity chunks, 0 poi chunks in world 'world_nether' in 0.39s
Feb 17 19:18:31 minecraft lazymc-v0.2.9-linux-x64-static[1765]: [19:18:31 INFO]: ThreadedAnvilChunkStorage (DIM-1): All chunks are saved
Feb 17 19:18:31 minecraft lazymc-v0.2.9-linux-x64-static[1765]: [19:18:31 INFO]: Saving chunks for level 'ServerLevel[world_the_end]'/minecraft:the_end
Feb 17 19:18:31 minecraft lazymc-v0.2.9-linux-x64-static[1765]: [19:18:31 INFO]: [ChunkHolderManager] Waiting 60s for chunk system to halt for world 'world_the_end'
Feb 17 19:18:31 minecraft lazymc-v0.2.9-linux-x64-static[1765]: [19:18:31 INFO]: [ChunkHolderManager] Halted chunk system for world 'world_the_end'
Feb 17 19:18:31 minecraft lazymc-v0.2.9-linux-x64-static[1765]: [19:18:31 INFO]: [ChunkHolderManager] Saving all chunkholders for world 'world_the_end'
Feb 17 19:18:31 minecraft lazymc-v0.2.9-linux-x64-static[1765]: [19:18:31 INFO]: [ChunkHolderManager] Saved 529 block chunks, 529 entity chunks, 0 poi chunks in world 'world_the_end' in 0.09s
Feb 17 19:18:31 minecraft lazymc-v0.2.9-linux-x64-static[1765]: [19:18:31 INFO]: ThreadedAnvilChunkStorage (DIM1): All chunks are saved
Feb 17 19:18:31 minecraft lazymc-v0.2.9-linux-x64-static[1765]: [19:18:31 INFO]: ThreadedAnvilChunkStorage: All dimensions are saved
Feb 17 19:18:31 minecraft lazymc-v0.2.9-linux-x64-static[1765]: [19:18:31 INFO]: Flushing Chunk IO
Feb 17 19:18:31 minecraft lazymc-v0.2.9-linux-x64-static[1765]: [19:18:31 INFO]: Closing Thread Pool
Feb 17 19:18:31 minecraft lazymc-v0.2.9-linux-x64-static[1765]: 2023-02-17 19:18:31,634 Log4j2-AsyncAppenderEventDispatcher-1-Async WARN Advanced terminal features are not available in this environment
Feb 17 19:18:31 minecraft lazymc-v0.2.9-linux-x64-static[1765]: [19:18:31 INFO]: Closing Server
Feb 17 19:18:32 minecraft lazymc-v0.2.9-linux-x64-static[1505]:  WARN  lazymc          > Server process stopped with error code (exit status: 143)
Feb 17 19:18:34 minecraft lazymc-v0.2.9-linux-x64-static[1505]:  INFO  lazymc::monitor > Server is now sleeping

(It does seem like the error happens at the end, after each world and everything got saved, so I am personally not too worried about data loss... I think?)

marissa999 commented 1 year ago

Ok I am pretty sure that the SIGTERM is the issue, not the SIGINT. I just did a small experiment, without lazymc involved:

  1. I started my minecraft server in shell A. java -Xmx2048m -Xms512m -jar paper-1.19.3-404.jar
  2. Once the server was fully started in shell B I used ps aux to get the PID of the mc server process.
  3. I then executed kill -2 <PID> to stop the server with a SIGINT
  4. In shell A i saw the server shut down normally.
  5. In shell A I then executed echo $? to get the return code of the last process in that shell, which was the minecraft server. It printed 0.

I repeated the steps, but at step 3 instead of kill -2 I used kill -15 (SIGTERM). At step 5 after I executed the echo $? I then got the code 143, which is the same that lazymc returned.

It seems like it matters to the Minecraft server (or jvm?) if a SIGTERM or a SIGINT is used. I guess I could try to write a bash wrapper script, which once it received a sigterm it will forward a sigint. SIGTERM is normally the proper approach, and also what Systemd sends, so that is a bit weird from Minecraft, I think

timvisee commented 1 year ago

Thanks for testing this.

When I originally developed this I figured SIGTERM was the best, based documentation. But, maybe this is wrong. Minecraft's documentation is a mess and severely lacking.

@marissa999 with your server(s), does using SIGINT always exit gracefully?

In that case lazymc should maybe default to SIGINT.

Note that if stopping fails, a SIGKILL will be sent to force quit the server process to prevent it from getting stuck. I don't think that is relevant here though.

marissa999 commented 1 year ago

In my testing yesterday, a SIGINT always exit normally, with 0 and no errors. I did no testing with other minecraft server versions, but the one I mentioned.

I also just looked a bit more into this and for some reason there seems like not a lot is documented about this. I did find the following links though:

https://bugs.mojang.com/browse/MC-109811

https://serverfault.com/questions/695849/services-remain-in-failed-state-after-stopped-with-systemctl

So it seems like 143 is working by design? And also other programs like Docker do that, with 143 for sigterm. I thought you should always use 0 unless something weird happened, but apparently I was wrong? I have not experience with Java, JVM, Minecraft, or Exit codes though. Maybe a 143 Error could be ignored? Might be the best approach.

timvisee commented 1 year ago

Right! Thank you for diving into this.

I'll add 143 as valid exit code.

timvisee commented 1 year ago

I've released v0.2.10 which allows exit code 143.

Closing this in assumption the new version fixes the underlying issue. Feel free to open again if the issue persists.