BUG: service stop --force leaves Postgres running when one process's command line can't be read
Description
steampipe service stop --force can leave the Postgres service running while reporting success, and delete the service's running-info file. The next steampipe service start then fails with:
Error: service is running in an unknown state [PID: NNNN] - try killing it with steampipe service stop --forceFindAllSteampipePostgresInstances walks every process on the machine and returns an error for the whole scan if it cannot read any single process's command line — for example because that process exited during the scan. killInstanceIfAny treats that error as "no instances", so stopDBService(force=true) returns ServiceNotRunning with no error, and StopServices then removes the running-info file while Postgres keeps running.
Severity
MEDIUM - service stop --force is the documented recovery path, and it silently does nothing; the service is then left in the "unknown state" it tells the user to fix with the same command.
Reproduction
Intermittent; more likely on a machine with many short-lived processes (a typical developer Mac). Seen in tests/acceptance/test_files/ssl.bats on macOS:
steampipe service start, thensteampipe service restartsteampipe service stop --force— trace log showsFindAllSteampipePostgresInstances - error retrieving cmdline for pid NNNN: exit status 1, thenstopped DB Service; Postgres is not signalledsteampipe service startfails with "service is running in an unknown state"
Expected Behavior
A process whose command line cannot be read is skipped, and the scan still finds and stops the steampipe Postgres instances.
Current Behavior
The whole scan fails, nothing is stopped, and the running-info file is deleted.
Suggested Fix
Log and skip the unreadable process instead of returning, as killRunningDbInstance in pkg/db/db_local/backup.go already does for the same error.
Related Code
pkg/db/db_local/start_services.go-FindAllSteampipePostgresInstancesreturns on the firstCmdlineSliceWithContexterrorpkg/db/db_local/start_services.go-killInstanceIfAnytreats the error as "nothing running"pkg/db/db_local/stop_services.go-StopServicesremoves the running-info file whenstopDBServicereturns no error- Also affects
steampipe service status --all(cmd/service.go,showAllStatus) andkillRunningDbInstance(pkg/db/db_local/backup.go)
Source: turbot/steampipe