kou opened a new issue, #228:
URL: https://github.com/apache/arrow-flight-sql-postgresql/issues/228

   Tests are sometimes killed by `SIGUSR1` before they report any result:
   
   ```text
   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:
   
   ```text
   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`:
   
   ```cpp
   kill(request->localSession->peerPID, SIGUSR1);
   ```
   
   `localSession->peerPID` is copied from `session->executorPID` only once in 
`Proxy::process_connect_requests()`:
   
   ```cpp
   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:
   
      ```cpp
      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
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to