Skip to content

Commit

Permalink
servenv: Remove double close() logic
Browse files Browse the repository at this point in the history
The servenv.Run function already runs the close hooks once it finishes.
This means there's no use for deferring a `.Close()` since it double
executes all close hooks.

In fact, it leads to panics. For example, vttablet always panics on each
shutdown because the connection to the topo is already closed.

Signed-off-by: Dirkjan Bussink <[email protected]>
  • Loading branch information
dbussink committed Nov 3, 2023
1 parent 366f7d2 commit f8d7f32
Show file tree
Hide file tree
Showing 8 changed files with 0 additions and 15 deletions.
2 changes: 0 additions & 2 deletions go/cmd/mysqlctld/cli/mysqlctld.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ var (
Long: "`mysqlctld` is a gRPC server that can be used instead of the `mysqlctl` client tool.\n" +
"If the target directories are empty when it is invoked, it automatically performs initialization operations to bootstrap the `mysqld` instance before starting it.\n" +
"The `mysqlctld` process can subsequently receive gRPC commands from a `vttablet` to perform housekeeping operations like shutting down and restarting the `mysqld` instance as needed.\n\n" +

"{{< warning >}}\n" +
"`mysqld_safe` is not used so the `mysqld` process will not be automatically restarted in case of a failure.\n" +
"{{</ warning>}}\n\n" +
Expand Down Expand Up @@ -151,7 +150,6 @@ func run(cmd *cobra.Command, args []string) error {
cancel()

servenv.Init()
defer servenv.Close()

// Take mysqld down with us on SIGTERM before entering lame duck.
servenv.OnTermSync(func() {
Expand Down
1 change: 0 additions & 1 deletion go/cmd/vtaclcheck/cli/vtactlcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ var (

func run(cmd *cobra.Command, args []string) error {
servenv.Init()
defer servenv.Close()

opts := &vtaclcheck.Options{
ACLFile: aclFile,
Expand Down
1 change: 0 additions & 1 deletion go/cmd/vtbackup/cli/vtbackup.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ func init() {

func run(_ *cobra.Command, args []string) error {
servenv.Init()
defer servenv.Close()

ctx, cancel := context.WithCancel(context.Background())
servenv.OnClose(func() {
Expand Down
1 change: 0 additions & 1 deletion go/cmd/vtbench/cli/vtbench.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ func run(cmd *cobra.Command, args []string) error {
_ = cmd.Flags().Set("logtostderr", "true")

servenv.Init()
defer servenv.Close()

var clientProto vtbench.ClientProtocol
switch protocol {
Expand Down
1 change: 0 additions & 1 deletion go/cmd/vtctld/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ This is demonstrated in the example usage below.`,

func run(cmd *cobra.Command, args []string) error {
servenv.Init()
defer servenv.Close()

ts = topo.Open()
defer ts.Close()
Expand Down
1 change: 0 additions & 1 deletion go/cmd/vtgate/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ func run(cmd *cobra.Command, args []string) error {
defer exit.Recover()

servenv.Init()
defer servenv.Close()

ts := topo.Open()
defer ts.Close()
Expand Down
1 change: 0 additions & 1 deletion go/cmd/vttablet/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ vttablet \

func run(cmd *cobra.Command, args []string) error {
servenv.Init()
defer servenv.Close()

tabletAlias, err := topoproto.ParseTabletAlias(tabletPath)
if err != nil {
Expand Down
7 changes: 0 additions & 7 deletions go/vt/servenv/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package servenv

import (
"net"
"net/url"
"os"
"os/signal"
"strconv"
Expand Down Expand Up @@ -76,12 +75,6 @@ func Run(bindAddress string, port int) {
fireOnCloseHooks(onCloseTimeout)
}

// Close runs any registered exit hooks in parallel.
func Close() {
onCloseHooks.Fire()
ListeningURL = url.URL{}
}

// OnClose registers f to be run at the end of the app lifecycle.
// This happens after the lameduck period just before the program exits.
// All hooks are run in parallel.
Expand Down

0 comments on commit f8d7f32

Please sign in to comment.