Skip to content

Update pitchfork master_pid regex to avoid self-reference shell pid#306

Open
dobon wants to merge 1 commit intodiscourse:mainfrom
dobon:patch-1
Open

Update pitchfork master_pid regex to avoid self-reference shell pid#306
dobon wants to merge 1 commit intodiscourse:mainfrom
dobon:patch-1

Conversation

@dobon
Copy link

@dobon dobon commented Mar 1, 2026

I ran into an error about insufficient workers while trying to run the updater and upon investigation I found an apparent bug with the updater script/pitchfork adapter. The following snippet illustrates the problem:

root@07d212411142-app:/var/www/discourse# pgrep -f "pitchfork monitor"
30864
root@07d212411142-app:/var/www/discourse# rails c
Loading production environment (Rails 8.0.4)
discourse(prod)> `pgrep -f "pitchfork monitor"`
=> "11035 sh -c pgrep -f \"pitchfork monitor\"\n30864 pitchfork monitor - \n"
discourse(prod)> `pgrep -f "pitchfork monitor"`.strip.to_i
=> 12545
discourse(prod)> `pgrep -f "^pitchfork monitor"`.strip.to_i
=> 30864

The current regex is getting the pid of the pgrep shell command, rather than the actual pitchfork monitor (which gives the wrong master_pid, which means that no workers can be found belonging to that master_pid, which causes the updater script to fail). Using ^ anchor in the pgrep command avoids this problem.

```
root@07d212411142-app:/var/www/discourse# pgrep -f "pitchfork monitor"
30864
root@07d212411142-app:/var/www/discourse# rails c
Loading production environment (Rails 8.0.4)
discourse(prod)> `pgrep -af "pitchfork monitor"`
=> "11035 sh -c pgrep -af \"pitchfork monitor\"\n30864 pitchfork monitor - \n"
discourse(prod)> `pgrep -f "pitchfork monitor"`.strip.to_i
=> 12545
```

The current regex is getting the pid of the pgrep shell command, rather than the actual pitchfork monitor. Using ^ anchor avoids this problem.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant