@DaneEveritt Guard against a nil-pointer if the container is not found; references pterodactyl/panel#2000

This commit is contained in:
Dane Everitt 2020-05-08 20:19:44 -07:00
parent ced8a5bcbd
commit b2cf222a3a
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53

View File

@ -197,16 +197,31 @@ func (d *DockerEnvironment) Start() error {
return &suspendedError{}
}
c, err := d.Client.ContainerInspect(context.Background(), d.Server.Uuid)
if err != nil && !client.IsErrNotFound(err) {
return errors.WithStack(err)
}
if c, err := d.Client.ContainerInspect(context.Background(), d.Server.Uuid); err != nil {
// Do nothing if the container is not found, we just don't want to continue
// to the next block of code here. This check was inlined here to guard againt
// a nil-pointer when checking c.State below.
//
// @see https://github.com/pterodactyl/panel/issues/2000
if !client.IsErrNotFound(err) {
return errors.WithStack(err)
}
} else {
// If the server is running update our internal state and continue on with the attach.
if c.State.Running {
d.Server.SetState(ProcessRunningState)
// No reason to try starting a container that is already running.
if c.State.Running {
d.Server.SetState(ProcessRunningState)
return d.Attach()
}
return d.Attach()
// Truncate the log file so we don't end up outputting a bunch of useless log information
// to the websocket and whatnot. Check first that the path and file exist before trying
// to truncate them.
if _, err := os.Stat(c.LogPath); err == nil {
if err := os.Truncate(c.LogPath, 0); err != nil {
return errors.WithStack(err)
}
}
}
d.Server.SetState(ProcessStartingState)
@ -221,15 +236,6 @@ func (d *DockerEnvironment) Start() error {
return errors.WithStack(err)
}
// Truncate the log file so we don't end up outputting a bunch of useless log information
// to the websocket and whatnot. Check first that the path and file exist before trying
// to truncate them.
if _, err := os.Stat(c.LogPath); err == nil {
if err := os.Truncate(c.LogPath, 0); err != nil {
return errors.WithStack(err)
}
}
// Update the configuration files defined for the server before beginning the boot process.
// This process executes a bunch of parallel updates, so we just block until that process
// is completed. Any errors as a result of this will just be bubbled out in the logger,