SIGTERM is not handled properly in CLI / --once modes

Open
#848 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
cpp, php

Research direction

Start by reproducing the behavior with the provided PHP test code, using kphp -M cli ./test.php and the --once command, then send SIGTERM once and twice as shown. Trace the CLI and server --once signal-handling paths; done means the first SIGTERM exits after the configured wait and invokes register_shutdown_function callbacks.

Written by the indexing model from the issue text.

Description

Problem

KPHP compiled program in CLI/--once modes do not handle SIGTERM signal properly:

  • after first SIGTERM nothing happens for indefinite time
  • after second SIGTERM application exits but does not call functions registered by register_shutdown_function
Test code
<?php
register_shutdown_function(function () {
  var_dump('shutting down');
});

$start = microtime(true);

while (true) {
  sleep(1);
  $elapsed = (int)(microtime(true) - $start);
  var_dump("working for ${elapsed} seconds");
}
Compilation

cli mode:

kphp -M cli ./test.php

normal mode

kphp ./test.php
Run

Server --once mode and CLI mode have the same behavior:

./kphp_out/server --once --sigterm-wait-time 1 & # OR ./kphp_out/cli &
string(21) "working for 1 seconds"
string(21) "working for 2 seconds"
string(21) "working for 3 seconds"
string(21) "working for 4 seconds"
string(21) "working for 5 seconds"
string(21) "working for 6 seconds"
string(21) "working for 7 seconds"
string(21) "working for 8 seconds"
string(21) "working for 9 seconds"   <--------------- kill $!
[pid 223] [time 1686236327] SIGTERM handled.
string(21) "working for 9 seconds"
string(22) "working for 10 seconds"
string(22) "working for 11 seconds"
string(22) "working for 12 seconds"
string(22) "working for 13 seconds"
string(22) "working for 14 seconds"
string(22) "working for 15 seconds"
string(22) "working for 16 seconds"   <--------------- kill $! again
[pid 223] [time 1686236334] SIGTERM handled immediately.
Dominant language
C++
Stars
1.5k
Forks
116
Avg merge
5d 17h
Merged PRs (30d)
11

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from VKCOM/kphp

All issues in VKCOM/kphp

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.