timeout.go 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. // SystemSave is the timeout for saving a compute system
  25. SystemSave time.Duration = defaultTimeout
  26. // SyscallWatcher is the timeout before warning of a potential stuck platform syscall.
  27. SyscallWatcher time.Duration = defaultTimeout
  28. // Tar2VHD is the timeout for the tar2vhd operation to complete
  29. Tar2VHD time.Duration = defaultTimeout
  30. // ExternalCommandToStart is the timeout for external commands to start
  31. ExternalCommandToStart = defaultTimeout
  32. // ExternalCommandToComplete is the timeout for external commands to complete.
  33. // Generally this means copying data from their stdio pipes.
  34. ExternalCommandToComplete = defaultTimeout
  35. // TestDRetryLoop is the timeout for testd retry loop when onlining a SCSI disk in LCOW
  36. TestDRetryLoop = defaultTimeoutTestdRetry
  37. )
  38. func init() {
  39. SystemCreate = durationFromEnvironment("HCSSHIM_TIMEOUT_SYSTEMCREATE", SystemCreate)
  40. SystemStart = durationFromEnvironment("HCSSHIM_TIMEOUT_SYSTEMSTART", SystemStart)
  41. SystemPause = durationFromEnvironment("HCSSHIM_TIMEOUT_SYSTEMPAUSE", SystemPause)
  42. SystemResume = durationFromEnvironment("HCSSHIM_TIMEOUT_SYSTEMRESUME", SystemResume)
  43. SystemSave = durationFromEnvironment("HCSSHIM_TIMEOUT_SYSTEMSAVE", SystemSave)
  44. SyscallWatcher = durationFromEnvironment("HCSSHIM_TIMEOUT_SYSCALLWATCHER", SyscallWatcher)
  45. Tar2VHD = durationFromEnvironment("HCSSHIM_TIMEOUT_TAR2VHD", Tar2VHD)
  46. ExternalCommandToStart = durationFromEnvironment("HCSSHIM_TIMEOUT_EXTERNALCOMMANDSTART", ExternalCommandToStart)
  47. ExternalCommandToComplete = durationFromEnvironment("HCSSHIM_TIMEOUT_EXTERNALCOMMANDCOMPLETE", ExternalCommandToComplete)
  48. TestDRetryLoop = durationFromEnvironment("HCSSHIM_TIMEOUT_TESTDRETRYLOOP", TestDRetryLoop)
  49. }
  50. func durationFromEnvironment(env string, defaultValue time.Duration) time.Duration {
  51. envTimeout := os.Getenv(env)
  52. if len(envTimeout) > 0 {
  53. e, err := strconv.Atoi(envTimeout)
  54. if err == nil && e > 0 {
  55. return time.Second * time.Duration(e)
  56. }
  57. }
  58. return defaultValue
  59. }