Skip to content

Commit

Permalink
fix: hanging process functionality killing wrong processes (#2419)
Browse files Browse the repository at this point in the history
When using backend data directories like `Quietdev`, `Quietdev1`, `Quietdev2',
restarting the process using `Quietdev` can result in that process killing the
other backend processes due to the grep command used for finding hanging
processes. Example:

```
user (Quietdev1):
desktop:main:main Forked backend, PID: 214543

owner (Quietdev):
Found 1 hanging backend process(es) with pid(s) 214543. Killing...
```
  • Loading branch information
Lucas Leblow authored Apr 8, 2024
1 parent 7786e26 commit c35ec3c
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions packages/common/src/process.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { type SupportedPlatform } from '@quiet/types'

/**
* Commands should output hanging backend pid
*/
export const hangingBackendProcessCommand = ({
backendBundlePath,
dataDir,
}: {
backendBundlePath: string
dataDir: string
}): string => {
/**
* Commands should output hanging backend pid
*/
const byPlatform = {
android: `pgrep -af "${backendBundlePath}" | grep -v pgrep | grep "${dataDir}" | awk '{print $1}'`,
linux: `pgrep -af "${backendBundlePath}" | grep -v egrep | grep "${dataDir}" | awk '{print $1}'`,
darwin: `ps -A | grep "${backendBundlePath}" | grep -v egrep | grep "${dataDir}" | awk '{print $1}'`,
android: `pgrep -af "${backendBundlePath}" | grep -v pgrep | grep -e "${dataDir}$" -e "${dataDir}[[:space:]]" | awk '{print $1}'`,
linux: `pgrep -af "${backendBundlePath}" | grep -v egrep | grep -e "${dataDir}$" -e "${dataDir}[[:space:]]" | awk '{print $1}'`,
darwin: `ps -A | grep "${backendBundlePath}" | grep -v egrep | grep -e "${dataDir}$" -e "${dataDir}[[:space:]]" | awk '{print $1}'`,
win32: `powershell "Get-WmiObject Win32_process -Filter {commandline LIKE '%${backendBundlePath.replace(
/\\/g,
'\\\\'
Expand Down

0 comments on commit c35ec3c

Please sign in to comment.