You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2021/08/30 13:36:22 UTC

[GitHub] [apisix-dashboard] bisakhmondal commented on a change in pull request #2054: fix: perform pid lookup for existing pid file

bisakhmondal commented on a change in pull request #2054:
URL: https://github.com/apache/apisix-dashboard/pull/2054#discussion_r698493939



##########
File path: api/internal/utils/pid.go
##########
@@ -18,19 +18,62 @@
 package utils
 
 import (
+	"bytes"
 	"fmt"
 	"io/ioutil"
 	"os"
+	"runtime"
 	"strconv"
+	"syscall"
+	"time"
+
+	"github.com/pkg/errors"
 )
 
 // WritePID write pid to the given file path.
 func WritePID(filepath string, forceStart bool) error {
-	if pid, err := ReadPID(filepath); err == nil {
-		if !forceStart {
-			return fmt.Errorf("Instance of Manager API maybe running with a pid %d. If not, please run Manager API with '-f' or '--force' flag\n", pid)
+	pidStatAction := func() error {
+		pid, err := ReadPID(filepath)
+		if err != nil {
+			return nil

Review comment:
       Hi @nic-chen , I am following a fail-fast approach. The ReadPID returns error means it will most likely be `os.PathError` i.e. the file does not exist.  Instead of writing whole block as `if err==nil` (previous implementation),  I was trying to introduce less spaghetti code. 
   
   If you want, we definitely can improve the err to something like
   
   ```go
   if err != nil {
     if _, ok := err.(*os.PathError); ok {
        return nil // No pid file --> no running instance
     }
     return err
   }
   ```
   Let me know what you think. Thanks.




-- 
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: notifications-unsubscribe@apisix.apache.org

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