Skip to content

Commit 4daf8ca

Browse files
committed
fix merge
1 parent a75b8c8 commit 4daf8ca

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

modules/process/manager.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ func (pm *Manager) AddTypedContext(parent context.Context, description, processT
106106
// Most processes will not need to use the cancel function but there will be cases whereby you want to cancel the process but not immediately remove it from the
107107
// process table.
108108
func (pm *Manager) AddContextTimeout(parent context.Context, timeout time.Duration, description string) (ctx context.Context, cancel context.CancelFunc, finshed FinishedFunc) {
109+
if timeout <= 0 {
110+
// it's meaningless to use timeout <= 0, and it must be a bug! so we must panic here to tell developers to make the timeout correct
111+
panic("the timeout must be greater than zero, otherwise the context will be cancelled immediately")
112+
}
113+
109114
ctx, cancel = context.WithTimeout(parent, timeout)
110115

111116
ctx, _, finshed = pm.Add(ctx, description, cancel, NormalProcessType, true)

modules/process/manager_exec.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ func (pm *Manager) ExecDirEnv(ctx context.Context, timeout time.Duration, dir, d
3636
}
3737

3838
// ExecDirEnvStdIn runs a command in given path and environment variables with provided stdIN, and waits for its completion
39-
// up to the given timeout (or DefaultTimeout if -1 is given).
39+
// up to the given timeout (or DefaultTimeout if timeout <= 0 is given).
4040
// Returns its complete stdout and stderr
4141
// outputs and an error, if any (including timeout)
4242
func (pm *Manager) ExecDirEnvStdIn(ctx context.Context, timeout time.Duration, dir, desc string, env []string, stdIn io.Reader, cmdName string, args ...string) (string, string, error) {
43-
if timeout == -1 {
43+
if timeout <= 0 {
4444
timeout = 60 * time.Second
4545
}
4646

0 commit comments

Comments
 (0)