You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@solr.apache.org by GitBox <gi...@apache.org> on 2021/08/07 11:39:47 UTC

[GitHub] [solr] colvinco opened a new pull request #250: SOLR-15558: Identify zombie processes when stopping

colvinco opened a new pull request #250:
URL: https://github.com/apache/solr/pull/250


   https://issues.apache.org/jira/browse/SOLR-15558
   
   <!--
   _(If you are a project committer then you may remove some/all of the following template.)_
   
   Before creating a pull request, please file an issue in the ASF Jira system for Solr:
   
   * https://issues.apache.org/jira/projects/SOLR
   
   You will need to create an account in Jira in order to create an issue.
   
   The title of the PR should reference the Jira issue number in the form:
   
   * SOLR-####: <short description of problem or changes>
   
   SOLR must be fully capitalized. A short description helps people scanning pull requests for items they can work on.
   
   Properly referencing the issue in the title ensures that Jira is correctly updated with code review comments and commits. -->
   
   
   # Description
   
   Identify zombie processes when stopping Solr, since a zombie has already terminated there is no need to wait 3 minutes.
   Also simplified some of the other `ps` usage to filter by id rather than `grep`ing.
   
   # Solution
   
   `ps -o stat --no-headers $SOLR_PID` will output the STAT for a process (if it is running). If the process is a Zombie/defunct then the stat will be `Z`. If the process isn't running then no output will be generated.
   Also simplified some of the other `ps` usage to filter by id rather than `grep`ing.
   GitHub makes the diff look bigger than it is
   
   # Tests
   
   Manually checked on Ubuntu 16.04.6 in a docker container, by starting and stopping Solr.
   
   When running `solr stop` inside a container that was started with `docker run -dit <image> tail -f /dev/null` [the docker PID 1 reaping problem occurs](https://issues.apache.org/jira/browse/SOLR-15558) and the following output is generated without this patch (and 3 minutes elapses):
   ```
   root@6683526ba504:/opt/solr-8.9.0# bin/solr stop
   Sending stop command to Solr running on port 8983 ... waiting up to 180 seconds to allow Jetty process 454 to stop gracefully.
   Solr process 454 is still running; jattach threaddumping it now.
   Could not start attach mechanism: No such file or directory
   Solr process 454 is still running; forcefully killing it now.
   Killed process 454
   ERROR: Failed to kill previous Solr Java process 454 ... script fails.
   ```
   with this patch:
   ```
   root@b457f11bf485:/opt/solr-8.9.0# bin/solr stop
   Sending stop command to Solr running on port 8983 ... waiting up to 180 seconds to allow Jetty process 2288 to stop gracefully.
   Solr process 2288 has terminated abnormally. Solr has exited but a zombie process entry remains.
   ```
   On a container that is started with  `docker run -dit --init <image> tail -f /dev/null` the reaping problem doesn't occur and the following output is generated with or without the patch and the process terminates normally:
   ```
   root@262baa4c3c28:/opt/solr-8.9.0# bin/solr stop
   Sending stop command to Solr running on port 8983 ... waiting up to 180 seconds to allow Jetty process 135 to stop gracefully.
   ```
   
   
   # Checklist
   
   Please review the following and check all that apply:
   
   - [x] I have reviewed the guidelines for [How to Contribute](https://wiki.apache.org/solr/HowToContribute) and my code conforms to the standards described there to the best of my ability.
   - [x] I have created a Jira issue and added the issue ID to my pull request title.
   - [x] I have given Solr maintainers [access](https://help.github.com/en/articles/allowing-changes-to-a-pull-request-branch-created-from-a-fork) to contribute to my PR branch. (optional but recommended)
   - [x] I have developed this patch against the `main` branch.
   - [ ] I have run `./gradlew check`.
   - [ ] I have added tests for my changes.
   - [ ] I have added documentation for the [Reference Guide](https://github.com/apache/solr/tree/main/solr/solr-ref-guide)
   


-- 
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: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] colvinco commented on pull request #250: SOLR-15558: Identify zombie processes when stopping

Posted by GitBox <gi...@apache.org>.
colvinco commented on pull request #250:
URL: https://github.com/apache/solr/pull/250#issuecomment-1028142035


   Yes that seems to work fine. I've used `stat=''` rather than `stat= ` to try and be a bit more verbose, hopefully that works everywhere.


-- 
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: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] madrob commented on pull request #250: SOLR-15558: Identify zombie processes when stopping

Posted by GitBox <gi...@apache.org>.
madrob commented on pull request #250:
URL: https://github.com/apache/solr/pull/250#issuecomment-1027097574


   This doesn't work on my local macOS Monterey 12.2
   
   ```
   $ ps -o stat --no-headers 30425
   ps: illegal option -- -
   usage: ps [-AaCcEefhjlMmrSTvwXx] [-O fmt | -o fmt] [-G gid[,gid...]]
             [-g grp[,grp...]] [-u [uid,uid...]]
             [-p pid[,pid...]] [-t tty[,tty...]] [-U user[,user...]]
          ps [-L]
   ```
   
   However, the following seems to work:
   
   ```
   $ ps -o stat= 30425
   S
   ```
   
   Can you check if this same syntax will work on Linux?


-- 
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: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] iMichka commented on pull request #250: SOLR-15558: Identify zombie processes when stopping

Posted by GitBox <gi...@apache.org>.
iMichka commented on pull request #250:
URL: https://github.com/apache/solr/pull/250#issuecomment-1026260307


   Hi. I am maintainer of Homebrew, a package manager for macOS and Linux.
   We build and test `solr` in docker, and we have been hit by this issue.
   I tested your patch https://github.com/Homebrew/homebrew-core/pull/94188 and it fixed the failure.
   
   The tests also pass on the 3 macOS versions we build for. CI is still running but it already looks good on our side.
   
   Can this PR be reviewed and maybe included in the next release?


-- 
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: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] colvinco commented on a change in pull request #250: SOLR-15558: Identify zombie processes when stopping

Posted by GitBox <gi...@apache.org>.
colvinco commented on a change in pull request #250:
URL: https://github.com/apache/solr/pull/250#discussion_r799289796



##########
File path: solr/bin/solr
##########
@@ -884,8 +887,12 @@ function stop_solr() {
     sleep 10
   fi
 
-  CHECK_PID=`ps auxww | awk '{print $2}' | grep -w $SOLR_PID | sort -r | tr -d ' '`
-  if [ "$CHECK_PID" != "" ]; then
+  STAT=`ps -o stat='' $SOLR_PID | tr -d ' '`
+  if [ "$STAT" == "Z" ]; then
+    # This can happen if, for example, you are running Solr inside a docker container with multiple processes
+    # rather than running it is as the only service. The --init flag on docker avoids that particular problem.
+    echo -e "Solr process $SOLR_PID has terminated abnormally. Solr has exited but a zombie process entry remains."

Review comment:
       Fair question. I think you're right that it should exit 1, since something is wrong.




-- 
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: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] colvinco commented on pull request #250: SOLR-15558: Identify zombie processes when stopping

Posted by GitBox <gi...@apache.org>.
colvinco commented on pull request #250:
URL: https://github.com/apache/solr/pull/250#issuecomment-1026658180


   @madrob - could you possibly review this?


-- 
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: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] colvinco commented on pull request #250: SOLR-15558: Identify zombie processes when stopping

Posted by GitBox <gi...@apache.org>.
colvinco commented on pull request #250:
URL: https://github.com/apache/solr/pull/250#issuecomment-1029795985


   Thank you, changes made


-- 
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: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] madrob commented on a change in pull request #250: SOLR-15558: Identify zombie processes when stopping

Posted by GitBox <gi...@apache.org>.
madrob commented on a change in pull request #250:
URL: https://github.com/apache/solr/pull/250#discussion_r798964034



##########
File path: solr/bin/solr
##########
@@ -884,8 +887,12 @@ function stop_solr() {
     sleep 10
   fi
 
-  CHECK_PID=`ps auxww | awk '{print $2}' | grep -w $SOLR_PID | sort -r | tr -d ' '`
-  if [ "$CHECK_PID" != "" ]; then
+  STAT=`ps -o stat='' $SOLR_PID | tr -d ' '`
+  if [ "$STAT" == "Z" ]; then
+    # This can happen if, for example, you are running Solr inside a docker container with multiple processes
+    # rather than running it is as the only service. The --init flag on docker avoids that particular problem.
+    echo -e "Solr process $SOLR_PID has terminated abnormally. Solr has exited but a zombie process entry remains."

Review comment:
       Is this considered an error condition? I'm not sure. Maybe worthwhile to `exit 1` still? I'm not sure what your code calling this script would expect.

##########
File path: solr/bin/solr
##########
@@ -842,34 +842,37 @@ function stop_solr() {
   STOP_KEY="$3"
   SOLR_PID="$4"
 
-  if [ "$SOLR_PID" != "" ]; then
-    echo -e "Sending stop command to Solr running on port $SOLR_PORT ... waiting up to $SOLR_STOP_WAIT seconds to allow Jetty process $SOLR_PID to stop gracefully."
-    "$JAVA" $SOLR_SSL_OPTS $AUTHC_OPTS -jar "$DIR/start.jar" "STOP.PORT=$THIS_STOP_PORT" "STOP.KEY=$STOP_KEY" --stop || true
-      (loops=0
-      while true
-      do
-        CHECK_PID=`ps auxww | awk '{print $2}' | grep -w $SOLR_PID | sort -r | tr -d ' '`
-        if [ "$CHECK_PID" != "" ]; then
-          slept=$((loops * 2))
-          if [ $slept -lt $SOLR_STOP_WAIT ]; then
-            sleep 2
-            loops=$[$loops+1]
-          else
-            exit # subshell!
-          fi
-        else
-          exit # subshell!
-        fi
-      done) &
-    spinner $!
-    rm -f "$SOLR_PID_DIR/solr-$SOLR_PORT.pid"
-  else
+  if [ -z "$SOLR_PID"  ]; then

Review comment:
       nit: can we change this test to `-n` so that we minimize the diff a little bit? Makes it easier to review.




-- 
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: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] janhoy commented on pull request #250: SOLR-15558: Identify zombie processes when stopping

Posted by GitBox <gi...@apache.org>.
janhoy commented on pull request #250:
URL: https://github.com/apache/solr/pull/250#issuecomment-1030139879


   Have you run the entire test suite, including `TestSolrCLIRunExample`, which seems to start the example using the bin/solr script and then stop it again...


-- 
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: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] madrob closed pull request #250: SOLR-15558: Identify zombie processes when stopping

Posted by GitBox <gi...@apache.org>.
madrob closed pull request #250:
URL: https://github.com/apache/solr/pull/250


   


-- 
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: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org