mirror of
https://github.com/moby/moby.git
synced 2026-08-13 17:06:44 +00:00
api/server: delete Wait method
It's surprising that the method to begin serving requests is named Wait. And it is unidiomatic: it is a synchronous call, but it sends its return value to the channel passed in as an argument instead of just returning the value. And ultimately it is just a trivial wrapper around serveAPI. Export the ServeAPI method instead so callers can decide how to call and synchronize around it. Call ServeAPI synchronously on the main goroutine in cmd/dockerd. The goroutine and channel which the Wait() API demanded are superfluous after all. The notifyReady() call was always concurrent and asynchronous with respect to serving the API (its implementation spawns a goroutine) so it makes no difference whether it is called before ServeAPI() or after `go ServeAPI()`. Signed-off-by: Cory Snider <csnider@mirantis.com>
This commit is contained in:
@@ -239,18 +239,16 @@ func (cli *DaemonCli) start(opts *daemonOptions) (err error) {
|
||||
|
||||
cli.setupConfigReloadTrap()
|
||||
|
||||
// The serve API routine never exits unless an error occurs
|
||||
// We need to start it as a goroutine and wait on it so
|
||||
// daemon doesn't exit
|
||||
serveAPIWait := make(chan error)
|
||||
go cli.api.Wait(serveAPIWait)
|
||||
|
||||
// after the daemon is done setting up we can notify systemd api
|
||||
notifyReady()
|
||||
|
||||
// Daemon is fully initialized and handling API traffic
|
||||
// Wait for serve API to complete
|
||||
errAPI := <-serveAPIWait
|
||||
// Daemon is fully initialized. Start handling API traffic
|
||||
// and wait for serve API to complete.
|
||||
errAPI := cli.api.Serve()
|
||||
if errAPI != nil {
|
||||
logrus.WithError(errAPI).Error("ServeAPI error")
|
||||
}
|
||||
|
||||
c.Cleanup()
|
||||
|
||||
// notify systemd that we're shutting down
|
||||
|
||||
Reference in New Issue
Block a user