Skip to content

Commit

Permalink
client-change: adjust timeout duration when pprof port is in use
Browse files Browse the repository at this point in the history
The time for client to wait when port is in use is 1m. And the hint
is logged in the file. Now, the time changed to 10s and hint is
foreground to make the users know what the client is doing.
Besides, the log interval is also changed to approximately 5s to
make the screen clearer.

Signed-off-by: wanglei469 <[email protected]>
  • Loading branch information
wanglei469 authored and liushuoran001 committed Apr 13, 2022
1 parent 605eeac commit 8931e1f
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions client/fuse.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ const (
DefaultUDSName = "/tmp/ChubaoFS-fdstore.sock"

DefaultLogPath = "/var/log/chubaofs"

TimeOutPort = 10 * time.Second
)

var (
Expand Down Expand Up @@ -446,16 +448,15 @@ func startDaemon() error {
func waitListenAndServe(statusCh chan error, addr string, handler http.Handler) {
var err error
var loop int = 0
var interval int = (1 << 17) - 1
var interval int = (1 << 20) - 1
var listener net.Listener
var dynamicPort bool

if addr == ":" {
addr = ":0"
}

// FIXME: 1 min timeout?
timeout := time.Now().Add(time.Minute)
timeout := time.Now().Add(TimeOutPort)
for {
if listener, err = net.Listen("tcp", addr); err == nil {
break
Expand All @@ -464,18 +465,15 @@ func waitListenAndServe(statusCh chan error, addr string, handler http.Handler)
// addr is not released for use
if strings.Contains(err.Error(), "bind: address already in use") {
if loop&interval == 0 {
syslog.Printf("address %v is still in use\n", addr)
warnForeground("address %v is still in use, please wait ...\n", addr)
}
runtime.Gosched()
} else {
break
}
if time.Now().After(timeout) {
msg := fmt.Sprintf("address %v is still in use after "+
warnForeground("address %v is still in use after "+
"timeout, choose port automatically\n", addr)
syslog.Print(msg)
msg = "Warning: " + msg
daemonize.StatusWriter.Write([]byte(msg))
dynamicPort = true
break
}
Expand Down Expand Up @@ -690,3 +688,10 @@ func changeRlimit(val uint64) {
func freeOSMemory(w http.ResponseWriter, r *http.Request) {
debug.FreeOSMemory()
}

func warnForeground(format string, v ...interface{}) {
msg := fmt.Sprintf(format, v...)
syslog.Print(msg)
msg = "Warning: " + msg
daemonize.StatusWriter.Write([]byte(msg))
}

0 comments on commit 8931e1f

Please sign in to comment.