From c5ee4880809fd48d15c9818528ced254a34f2448 Mon Sep 17 00:00:00 2001 From: Dirkjan Bussink Date: Thu, 30 Nov 2023 18:31:02 +0100 Subject: [PATCH] mysqlctl: Error out on stale socket (#14650) Signed-off-by: Dirkjan Bussink --- go/vt/mysqlctl/mysqld.go | 6 +++--- go/vt/mysqlctl/mysqld_test.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/go/vt/mysqlctl/mysqld.go b/go/vt/mysqlctl/mysqld.go index 9864d909b2f..731e608a2c0 100644 --- a/go/vt/mysqlctl/mysqld.go +++ b/go/vt/mysqlctl/mysqld.go @@ -461,13 +461,13 @@ func cleanupLockfile(socket string, ts string) error { 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.Warningf("%v: not removing socket lock file: %v", ts, lockPath) - return nil + log.Errorf("%v: not removing socket lock file: %v with pid %v", ts, lockPath, p) + return fmt.Errorf("process %v is still running", p) } if !errors.Is(err, os.ErrProcessDone) { // Any errors except for the process being done // is unexpected here. - log.Errorf("%v: error checking process: %v", ts, err) + log.Errorf("%v: error checking process %v: %v", ts, p, err) return err } diff --git a/go/vt/mysqlctl/mysqld_test.go b/go/vt/mysqlctl/mysqld_test.go index b45ab5bd6d8..0caba8c904d 100644 --- a/go/vt/mysqlctl/mysqld_test.go +++ b/go/vt/mysqlctl/mysqld_test.go @@ -195,6 +195,6 @@ func TestCleanupLockfile(t *testing.T) { // If the lockfile exists, and the process is found, we don't clean it up. os.WriteFile("mysql.sock.lock", []byte(strconv.Itoa(os.Getpid())), 0o600) - assert.NoError(t, cleanupLockfile("mysql.sock", ts)) + assert.Error(t, cleanupLockfile("mysql.sock", ts)) assert.FileExists(t, "mysql.sock.lock") }