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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]