Skip to content

Commit

Permalink
Delay proxy listen until marked ready
Browse files Browse the repository at this point in the history
  • Loading branch information
benbjohnson committed Aug 10, 2023
1 parent 2948332 commit b5745bd
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions cmd/litefs/mount_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,6 @@ func (c *MountCommand) Run(ctx context.Context) (err error) {
return fmt.Errorf("cannot init store: %w", err)
} else if err := c.initHTTPServer(ctx); err != nil {
return fmt.Errorf("cannot init http server: %w", err)
} else if err := c.initProxyServer(ctx); err != nil {
return fmt.Errorf("cannot init proxy server: %w", err)
}

// Instantiate leaser.
Expand Down Expand Up @@ -268,9 +266,8 @@ func (c *MountCommand) Run(ctx context.Context) (err error) {

// Start the proxy server before the subcommand in case we need to hold
// requests after we promote but before the server is ready.
if c.ProxyServer != nil {
c.ProxyServer.Serve()
log.Printf("proxy server listening on: %s", c.ProxyServer.URL())
if err := c.runProxyServer(ctx); err != nil {
return fmt.Errorf("cannot run proxy server: %w", err)
}

// Execute subcommand, if specified in config.
Expand Down Expand Up @@ -480,7 +477,7 @@ func (c *MountCommand) initHTTPServer(ctx context.Context) error {
return nil
}

func (c *MountCommand) initProxyServer(ctx context.Context) error {
func (c *MountCommand) runProxyServer(ctx context.Context) error {
// Skip if there's no target set.
if c.Config.Proxy.Target == "" {
log.Printf("no proxy target set, skipping proxy")
Expand All @@ -507,6 +504,10 @@ func (c *MountCommand) initProxyServer(ctx context.Context) error {
return err
}
c.ProxyServer = server

c.ProxyServer.Serve()
log.Printf("proxy server listening on: %s", c.ProxyServer.URL())

return nil
}

Expand Down

0 comments on commit b5745bd

Please sign in to comment.