Skip to content

Commit

Permalink
Merge pull request #1695 from skalenetwork/bug/SKALED-1623-sigterm-at…
Browse files Browse the repository at this point in the history
…-exit

Bug/skaled 1623 sigterm at exit
  • Loading branch information
DmytroNazarenko authored Nov 21, 2023
2 parents 112dd40 + 22eed15 commit 7571104
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
1 change: 1 addition & 0 deletions .github/workflows/functional-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
with:
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
repository: skalenetwork/skale-ci-integration_tests
ref: v3.18.0
submodules: recursive
- name: Set up Node
uses: actions/setup-node@v3.4.0
Expand Down
39 changes: 21 additions & 18 deletions libdevcore/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,18 @@ void ExitHandler::exitHandler( int s ) {
}

void ExitHandler::exitHandler( int nSignalNo, ExitHandler::exit_code_t ec ) {
std::string strMessagePrefix = ExitHandler::shouldExit() ?
cc::error( "\nStop flag was already raised on. " ) +
cc::fatal( "WILL FORCE TERMINATE." ) +
cc::error( " Caught (second) signal. " ) :
cc::error( "\nCaught (first) signal. " );
std::cerr << strMessagePrefix << cc::error( skutils::signal::signal2str( nSignalNo ) )
<< "\n\n";
std::cerr.flush();
std::string strMessagePrefix;
if ( nSignalNo > 0 ) {
strMessagePrefix = ( ExitHandler::shouldExit() && s_nStopSignal > 0 ) ?
string( "\nStop flag was already raised on. " ) +
"WILL FORCE TERMINATE." + " Caught (second) signal. " :
"\nCaught (first) signal. ";
} else {
strMessagePrefix = ExitHandler::shouldExit() ?
string( "\nInternal exit requested while already exiting. " ) :
"\nInternal exit initiated. ";
}
std::cerr << strMessagePrefix << skutils::signal::signal2str( nSignalNo ) << "\n\n";

switch ( nSignalNo ) {
case SIGINT:
Expand Down Expand Up @@ -102,10 +106,10 @@ void ExitHandler::exitHandler( int nSignalNo, ExitHandler::exit_code_t ec ) {
auto start_time = std::chrono::steady_clock::now();

std::thread( [nSignalNo, start_time]() {
std::cerr << ( "\n" + cc::fatal( "SELF-KILL:" ) + " " + cc::error( "Will sleep " ) +
cc::size10( ExitHandler::KILL_TIMEOUT ) +
cc::error( " seconds before force exit..." ) + "\n\n" );
std::cerr.flush();
std::cerr << ( "\n" + string( "SELF-KILL:" ) + " " + "Will sleep " +
cc::size10( ExitHandler::KILL_TIMEOUT ) +
" seconds before force exit..." ) +
"\n\n";

clog( VerbosityInfo, "exit" ) << "THREADS timer started";

Expand Down Expand Up @@ -133,11 +137,10 @@ void ExitHandler::exitHandler( int nSignalNo, ExitHandler::exit_code_t ec ) {
std::this_thread::sleep_for( 100ms );
}

std::cerr << ( "\n" + cc::fatal( "SELF-KILL:" ) + " " +
cc::error( "Will force exit after sleeping " ) +
std::cerr << ( "\n" + string( "SELF-KILL:" ) + " " +
"Will force exit after sleeping " +
cc::size10( ExitHandler::KILL_TIMEOUT ) + cc::error( " second(s)" ) +
"\n\n" );
std::cerr.flush();

// TODO deduplicate this with main() before return
ExitHandler::exit_code_t ec = ExitHandler::requestedExitCode();
Expand All @@ -153,9 +156,9 @@ void ExitHandler::exitHandler( int nSignalNo, ExitHandler::exit_code_t ec ) {

// nice exit here:

if ( ExitHandler::shouldExit() ) {
std::cerr << ( "\n" + cc::fatal( "SIGNAL-HANDLER:" ) + " " +
cc::error( "Will force exit now..." ) + "\n\n" );
// TODO deduplicate with first if()
if ( ExitHandler::shouldExit() && s_nStopSignal > 0 && nSignalNo > 0 ) {
std::cerr << ( "\n" + string( "SIGNAL-HANDLER:" ) + " " + "Will force exit now...\n\n" );
_exit( 13 );
}

Expand Down

0 comments on commit 7571104

Please sign in to comment.