-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mysqlctl: Improve handling of the lock file #15404
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -460,6 +460,10 @@ | |
log.Errorf("%v: error parsing pid from lock file: %v", ts, err) | ||
return err | ||
} | ||
if os.Getpid() == p { | ||
log.Infof("%v: lock file at %s is ours, removing it", ts, lockPath) | ||
return os.Remove(lockPath) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we really want to do this? I'm curious how this happens, where we have the same PID we had before? Or am I missing something. That being said, I suppose it's fine since eventually the PID will get reused and could be reused by another mysqld process. In that case though I'm also not sure what "ours" really means in that context. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mattlord It can happen inside containers. Each container is unique and gets new PIDs so it's possible there to have PID reusage much more often. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, when using persistent storage for the lock file that lives across containers. Makes sense. Thanks! |
||
} | ||
proc, err := os.FindProcess(p) | ||
if err != nil { | ||
log.Errorf("%v: error finding process: %v", ts, err) | ||
|
@@ -469,7 +473,13 @@ | |
if err == nil { | ||
// If the process still exists, it's not safe to | ||
// remove the lock file, so we have to keep it around. | ||
log.Errorf("%v: not removing socket lock file: %v with pid %v", ts, lockPath, p) | ||
cmdline, err := os.ReadFile(fmt.Sprintf("/proc/%d/cmdline", p)) | ||
if err == nil { | ||
name := string(bytes.ReplaceAll(cmdline, []byte{0}, []byte(" "))) | ||
log.Errorf("%v: not removing socket lock file: %v with pid %v for %q", ts, lockPath, p, name) | ||
} else { | ||
log.Errorf("%v: not removing socket lock file: %v with pid %v (failed to read process name: %v)", ts, lockPath, p, err) | ||
} | ||
return fmt.Errorf("process %v is still running", p) | ||
} | ||
if !errors.Is(err, os.ErrProcessDone) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd take the opportunity to rename
ts
asts == *topo.Server
in the code base. :-)No idea why that was chosen for:
time start, I guess? Up to you if you want to change it.