Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hang during init on Windows if WMI is unavailable #74

Merged
merged 2 commits into from
Jun 9, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Added

### Changed
- Fixed Windows issue that caused a hang during `init()` if WMI wasn't ready. #74

### Deprecated

Expand Down
18 changes: 9 additions & 9 deletions sigar_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,6 @@ func init() {
// PROCESS_QUERY_LIMITED_INFORMATION cannot be used on 2003 or XP.
processQueryLimitedInfoAccess = syscall.PROCESS_QUERY_INFORMATION
}

if version.IsWindowsVistaOrGreater() {
// The minimum supported client for Win32_OperatingSystem is Windows Vista.
os, err := getWin32OperatingSystem()
if err == nil {
bootTime = &os.LastBootUpTime
}
}
}

func (self *LoadAverage) Get() error {
Expand All @@ -82,7 +74,15 @@ func (self *ProcFDUsage) Get(pid int) error {
func (self *Uptime) Get() error {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we don't have to worry about this being called concurrently?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we can't guarantee how the library will be used I would feel more comfortable if it was concurrency-safe. I will make a change.

if bootTime == nil {
// Minimum supported OS is Windows Vista.
return ErrNotImplemented{runtime.GOOS}
if !version.IsWindowsVistaOrGreater() {
return ErrNotImplemented{runtime.GOOS}
}

os, err := getWin32OperatingSystem()
if err != nil {
return errors.Wrap(err, "failed to get boot time using WMI")
}
bootTime = &os.LastBootUpTime
}

self.Length = time.Since(*bootTime).Seconds()
Expand Down