Fix logic for context based environment stopping

Uses dual contexts to handle stopping using a timed context, and also terminating the entire process loop if the parent context gets canceled.
This commit is contained in:
Dane Everitt
2022-01-31 19:09:08 -05:00
parent 84bbefdadc
commit cd67e5fdb9
9 changed files with 62 additions and 48 deletions

View File

@@ -3,6 +3,7 @@ package environment
import (
"context"
"os"
"time"
"github.com/pterodactyl/wings/events"
)
@@ -63,15 +64,11 @@ type ProcessEnvironment interface {
Stop(ctx context.Context) error
// WaitForStop waits for a server instance to stop gracefully. If the server is
// still detected as running after seconds, an error will be returned, or the server
// will be terminated depending on the value of the second argument.
WaitForStop(seconds uint, terminate bool) error
// WaitForStopWithContext works in the same fashion as WaitForStop, but accepts a
// context value and will stop waiting when the context is canceled. If the terminate
// option is true, the server will be terminate when the context is canceled if the
// server has not stopped at that point.
WaitForStopWithContext(ctx context.Context, terminate bool) error
// still detected as running after "duration", an error will be returned, or the server
// will be terminated depending on the value of the second argument. If the context
// provided is canceled the underlying wait conditions will be stopped and the
// entire loop will be ended (potentially without stopping or terminating).
WaitForStop(ctx context.Context, duration time.Duration, terminate bool) error
// Terminate stops a running server instance using the provided signal. This function
// is a no-op if the server is already stopped.