...

Source file src/github.com/Microsoft/hcsshim/internal/timeout/timeout.go

Documentation: github.com/Microsoft/hcsshim/internal/timeout

     1  package timeout
     2  
     3  import (
     4  	"os"
     5  	"strconv"
     6  	"time"
     7  )
     8  
     9  var (
    10  	// defaultTimeout is the timeout for most operations that is not overridden.
    11  	defaultTimeout = 4 * time.Minute
    12  
    13  	// defaultTimeoutTestdRetry is the retry loop timeout for testd to respond
    14  	// for a disk to come online in LCOW.
    15  	defaultTimeoutTestdRetry = 5 * time.Second
    16  )
    17  
    18  // External variables for HCSShim consumers to use.
    19  var (
    20  	// SystemCreate is the timeout for creating a compute system
    21  	SystemCreate time.Duration = defaultTimeout
    22  
    23  	// SystemStart is the timeout for starting a compute system
    24  	SystemStart time.Duration = defaultTimeout
    25  
    26  	// SystemPause is the timeout for pausing a compute system
    27  	SystemPause time.Duration = defaultTimeout
    28  
    29  	// SystemResume is the timeout for resuming a compute system
    30  	SystemResume time.Duration = defaultTimeout
    31  
    32  	// SystemSave is the timeout for saving a compute system
    33  	SystemSave time.Duration = defaultTimeout
    34  
    35  	// SyscallWatcher is the timeout before warning of a potential stuck platform syscall.
    36  	SyscallWatcher time.Duration = defaultTimeout
    37  
    38  	// Tar2VHD is the timeout for the tar2vhd operation to complete
    39  	Tar2VHD time.Duration = defaultTimeout
    40  
    41  	// ExternalCommandToStart is the timeout for external commands to start
    42  	ExternalCommandToStart = defaultTimeout
    43  
    44  	// ExternalCommandToComplete is the timeout for external commands to complete.
    45  	// Generally this means copying data from their stdio pipes.
    46  	ExternalCommandToComplete = defaultTimeout
    47  
    48  	// TestDRetryLoop is the timeout for testd retry loop when onlining a SCSI disk in LCOW
    49  	TestDRetryLoop = defaultTimeoutTestdRetry
    50  )
    51  
    52  func init() {
    53  	SystemCreate = durationFromEnvironment("HCSSHIM_TIMEOUT_SYSTEMCREATE", SystemCreate)
    54  	SystemStart = durationFromEnvironment("HCSSHIM_TIMEOUT_SYSTEMSTART", SystemStart)
    55  	SystemPause = durationFromEnvironment("HCSSHIM_TIMEOUT_SYSTEMPAUSE", SystemPause)
    56  	SystemResume = durationFromEnvironment("HCSSHIM_TIMEOUT_SYSTEMRESUME", SystemResume)
    57  	SystemSave = durationFromEnvironment("HCSSHIM_TIMEOUT_SYSTEMSAVE", SystemSave)
    58  	SyscallWatcher = durationFromEnvironment("HCSSHIM_TIMEOUT_SYSCALLWATCHER", SyscallWatcher)
    59  	Tar2VHD = durationFromEnvironment("HCSSHIM_TIMEOUT_TAR2VHD", Tar2VHD)
    60  	ExternalCommandToStart = durationFromEnvironment("HCSSHIM_TIMEOUT_EXTERNALCOMMANDSTART", ExternalCommandToStart)
    61  	ExternalCommandToComplete = durationFromEnvironment("HCSSHIM_TIMEOUT_EXTERNALCOMMANDCOMPLETE", ExternalCommandToComplete)
    62  	TestDRetryLoop = durationFromEnvironment("HCSSHIM_TIMEOUT_TESTDRETRYLOOP", TestDRetryLoop)
    63  }
    64  
    65  func durationFromEnvironment(env string, defaultValue time.Duration) time.Duration {
    66  	envTimeout := os.Getenv(env)
    67  	if len(envTimeout) > 0 {
    68  		e, err := strconv.Atoi(envTimeout)
    69  		if err == nil && e > 0 {
    70  			return time.Second * time.Duration(e)
    71  		}
    72  	}
    73  	return defaultValue
    74  }
    75  

View as plain text