laravel / octane

Supercharge your Laravel application's performance.
https://laravel.com/docs/octane
MIT License
3.73k stars 288 forks source link

Fix #851: When docker stop container, db connections still persists #853

Closed Focusnik closed 4 months ago

Focusnik commented 4 months ago

fix for https://github.com/laravel/octane/issues/851

Problem:

When we run octane+openswoole in docker container we can't use CTRL+C combination to stop the server. In docker case, container operation system will be ripped during stop phase. In common cases, docker send SIGTERM signal into bash/sh terminal, that is an owner of the container. But, terminal SIGTERM not propagated into "octane" commands.

Solution:

We should trap SIGHUP (terminal connection disrupted) signal, because only this signal will be sent into "octane" command, when terminal window closed. That can be easily tested on local machine: open OS task manager, find php stack and run "octane:start --server=swoole", and close the terminal process. You will see, that php processes still there. But if we trap SIGHUP signal, octane command will receive the signal to stop the server.

That's it

driesvints commented 4 months ago

@Focusnik please add a thorough description here and not just link to an issue.

Focusnik commented 4 months ago

@driesvints done

Focusnik commented 4 months ago

Also, i figured out some notice for docs mby. When we starting container in docker, we also make a volume for the logs folder. Octane creates server configuration file in the logs folder. So, when we scale docker container into >1 replicas with mounted logs directory we will have json file with pids for latest replica, that wrote into it. Developers must be careful with that and change state_file config value to some none mounted folder, so file will be unique per replica