timeout.go 2.6 KB

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