Skip to content

The server process may call kill(-1, SIGUSR1) #228

Closed

Description

@kou

Tests are sometimes killed by SIGUSR1 before they report any result:

User defined signal 1

This happened once in three runs of dev/release/verify-rc.sh in an Ubuntu 26.04 container. Not only the test runner but also other processes of the same user were killed.

The cause is that the server process may call kill(-1, SIGUSR1). kill(-1, ...) sends the signal to all processes that the calling process has permission to send signals to.

I replaced kill() in src/afs.cc with a wrapper that logs calls with pid <= 0, and ran the tests repeatedly under CPU load. The following calls were logged from the server process in one of the runs:

kill(-1, 10) at Proxy::process_write_requests() (11 times)
kill(-1, 10) at Proxy::process_update_prepared_statement_requests() (1 time)

Both of them use localSession->peerPID:

kill(request->localSession->peerPID, SIGUSR1);

localSession->peerPID is copied from session->executorPID only once in Proxy::process_connect_requests():

const auto initialized = session->initialized;
if (initialized && !DsaPointerIsValid(session->errorMessage))
{
	auto& localSession = localSessions_.find(request->sessionID)->second;
	localSession->valid = true;
	localSession->peerPID = session->executorPID;

But session->executorPID may still be InvalidPid (-1) at this point:

  1. The main process registers an executor and waits for it in MainProcessor::update_sessions(). session->executorPID is InvalidPid until WaitForBackgroundWorkerStartup() returns:

    WaitForBackgroundWorkerStartup(handle, &(session->executorPID));
  2. The executor process starts and sets session->initialized = true.

  3. The server process finds session->initialized == true and copies session->executorPID to localSession->peerPID.

  4. The main process returns from WaitForBackgroundWorkerStartup() and sets session->executorPID.

If 3. happens before 4., localSession->peerPID is -1 for the lifetime of the session. Nothing prevents this order because these processes access the session entry with shared locks.

We need to:

  • Set session->executorPID by the executor process itself (MyProcPid) before it sets session->initialized = true, so that session->executorPID is always valid when session->initialized is true
  • Check that the PID isn't InvalidPid before kill(). Processor::wait() and Executor::signal_server() already do this but the kill() calls that use session->executorPID, localSession->peerPID or sharedData_->serverPID don't

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions