Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Minetest server does not receive SIGTERM on container stop #65

Open
1 task done
zJudGenie opened this issue Oct 2, 2024 · 8 comments
Open
1 task done

Comments

@zJudGenie
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

When I stop the container, instead of stopping the minetest server gracefully(it should print [Main]: INFO: signal_handler(): got SIGTERM, shutting down. in the logs) it waits the timeout and then it kills it.

Expected Behavior

The server receives the SIGTERM and shuts down without waiting the 10s Docker timeout.

I think the problem is caused by the usage of s6 service, I don't know how to route the SIGTERM to the service.

Steps To Reproduce

  • Create a simple docker compose using the linuxserver minetest image
  • Start the server with docker compose start
  • Stop the container with docker compose stop

I think there is the same problem with just Docker

Environment

- OS: Ubuntu 22.04.4 LTS
- How docker service was installed: standard way

CPU architecture

x86-64

Docker creation

services:
  minetest:
    image: lscr.io/linuxserver/minetest:5.9.1
    container_name: minetest
    environment:
      - PUID=1001
      - PGID=1002
      - TZ=Europe/Rome 
    volumes:
      - ./data/minetest:/config/.minetest
    ports:
      - "0.0.0.0:30000:30000/udp"
    restart: unless-stopped

Container logs

2024-10-03 00:07:04: ACTION[Main]: [redef] Applied redefinition “Aligned Textures”
2024-10-03 00:07:04: ACTION[Main]: [redef] Applied redefinition “Proper Rotation”
2024-10-03 00:07:04: ACTION[Main]: [redef] Applied redefinition “Maximum Stack Size”
2024-10-03 00:07:04: ACTION[Main]: [redef] Applied redefinition “Grass Box Height”
2024-10-03 00:07:05: ACTION[Main]: World at [/config/.minetest/worlds/world]
2024-10-03 00:07:05: ACTION[Main]: Server for gameid="minigames" listening on 0.0.0.0:30000.
2024-10-03 00:07:05: ERROR[Server]: Server::dynamicAddMedia(): file "magiccompass_quikbild.png" already exists in media cache


-------------
  Separator
-------------

2024-10-03 00:13:22: [Main]: Automatically selecting world at [/config/.minetest/worlds/world]
2024-10-03 00:13:22: ACTION[Main]: [WHITELIST] Mod initialised, running version 1.2.4
2024-10-03 00:13:22: ACTION[Main]: [PANEL_LIB] Mod initialised, running version 3.2.1
2024-10-03 00:13:22: ACTION[Main]: [AUDIO_LIB] Mod initialised, running version 1.2.0-dev

You can see that the minetest server is killed without receiving the SIGTERM
@aptalca
Copy link
Member

aptalca commented Oct 3, 2024

Works fine here with the latest image

2024-10-03 00:27:48: [Main]: Automatically selecting world at [/config/.minetest/worlds/world]
2024-10-03 00:27:48: [Main]: Using game specified by --gameid on the command line
2024-10-03 00:27:48: ACTION[Main]: [log] modname="log"
2024-10-03 00:27:48: ACTION[Main]: [log] modpath="/config/.minetest/games/devtest/mods/log"
2024-10-03 00:27:48: ACTION[Main]: [log] worldpath="/config/.minetest/worlds/world"
2024-10-03 00:27:49: ACTION[Main]: [log] Callback: on_mods_loaded()
         __.               __.                 __.  
  _____ |__| ____   _____ /  |_  _____  _____ /  |_ 
 /     \|  |/    \ /  __ \    _\/  __ \/   __>    _\
|  Y Y  \  |   |  \   ___/|  | |   ___/\___  \|  |  
|__|_|  /  |___|  /\______>  |  \______>_____/|  |  
      \/ \/     \/         \/                  \/   
2024-10-03 00:27:49: ACTION[Main]: World at [/config/.minetest/worlds/world]
2024-10-03 00:27:49: ACTION[Main]: Server for gameid="devtest" listening on [::]:30000.
Connection to localhost (::1) 30000 port [udp/*] succeeded!
[ls.io-init] done.
2024-10-03 00:29:28: [Main]: INFO: signal_handler(): got SIGTERM, shutting down.
2024-10-03 00:29:28: ACTION[Main]: Server: Shutting down

Created the container with docker run -d --rm --name test -e CLI_ARGS="--gameid devtest" ghcr.io/linuxserver/minetest and issued a docker stop test while tailing the logs. It shuts down within a second or two.

@zJudGenie
Copy link
Author

zJudGenie commented Oct 3, 2024

Apparently it stops working when I bind the minetest folder volume with

volumes:
      - ./data/minetest:/config/.minetest

And I noticed that after doing that, when the server starts, these two lines are not printed

Connection to localhost (::1) 30000 port [udp/*] succeeded!
[ls.io-init] done.

Maybe the init phase is not completed.

I need to investigate further with a clean volume.

@zJudGenie
Copy link
Author

Problem found!
If you disable the IPv6 from the config

ipv6_server = false
enable_ipv6 = false

it does not conclude this init phase

Connection to localhost (::1) 30000 port [udp/*] succeeded!
[ls.io-init] done.

and the SIGTERM is not received by the process when you stop the container.
I don't know where the Connection to localhost come from, maybe I think from the s6-notifyoncheck command that executes netcat to try to reach the server

@zJudGenie
Copy link
Author

I can confirm that if I add -4 to use IPv4 in netcat here the init phase concludes and then if I stop the container it terminates gracefully.

I don't know if there is a way to let netcat understand if the server is not listening on IPv6.

@zJudGenie
Copy link
Author

there is a way to let netcat understand if the server is not listening on IPv6.

@aptalca Any hint?

@aptalca
Copy link
Member

aptalca commented Oct 4, 2024

I have no ipv6 capability so can't help you there

@zJudGenie
Copy link
Author

I have no ipv6 capability so can't help you there

From the log you posted

Connection to localhost (::1) 30000 port [udp/*] succeeded!

I see that also on your machine localhost gets resolved to ::1 and this cause the problem when the server is not listening on IPv6, also seems a common question https://unix.stackexchange.com/questions/530976/why-does-localhost-resolve-to-1-but-not-127-0-0-1

I think in this case we can just add the -4 option in the netcat command as the minetest server always listen on IPv4.

@LinuxServer-CI
Copy link
Contributor

This issue has been automatically marked as stale because it has not had recent activity. This might be due to missing feedback from OP. It will be closed if no further activity occurs. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Issues
Development

No branches or pull requests

3 participants