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

"Cannot change thread mode after it is set." error when calling disk.IOCounters on Windows #618

Closed
1 of 5 tasks
ericrange opened this issue Dec 14, 2018 · 4 comments
Closed
1 of 5 tasks

Comments

@ericrange
Copy link

Describe the bug
Sometimes i get an error when i want to get the io counters. But just sometimes...
"Cannot change thread mode after it is set."

To Reproduce

        parts, err := disk.Partitions(false)
	for _, part := range parts {
		u, errUsage := disk.Usage(part.Mountpoint)
		if errUsage != nil {
			logger.Error.Println(errUsage)
			continue
		}

		counters, errIO := disk.IOCounters(part.Mountpoint)
		if errIO != nil {
		=>	logger.Error.Println(errIO)
                "Cannot change thread mode after it is set."
                ....

Expected behavior
[A clear and concise description of what you expected to happen.]

Environment (please complete the following information):

  • Windows: [Windows Server 2012R2]
  • Linux: [paste contents of /etc/os-release and the result of uname -a]
  • Mac OS: [paste the result of sw_vers and uname -a
  • FreeBSD: [paste the result of freebsd-version -k -r -u and uname -a]
  • OpenBSD: [paste the result of uname -a]
@Lomanic Lomanic changed the title Cannot change thread mode after it is set. "Cannot change thread mode after it is set." error when calling disk.IOCounters on Windows Dec 14, 2018
@shirou
Copy link
Owner

shirou commented Dec 16, 2018

I have created this gist.
https://gist.github.com/shirou/004b2a859ed5f33ca659e431b7378d17

  • linux( 4.15.0-38-generic, go1.11.1) -> not error
  • freebsd(11.2-RELEASE-p4, go1.11.1) -> not error

I have not digged the golang source code, but is it windows only?

@ericrange
Copy link
Author

it seems that it is windows only. never got such an error for linux.
But as i said. it appears only "sometimes". Every 5 minutes, i guess.

@Lomanic
Copy link
Collaborator

Lomanic commented May 28, 2019

Solution is probably to remove calls to WMI (see #692 (comment)), performance counters might be an option here but way less easy to request than wmi (thanks to stackexchange/wmi package). Here is an example in Python, here is a promising package in Go.

@Lomanic
Copy link
Collaborator

Lomanic commented Mar 15, 2020

disk.IOCounters doesn't use WMI internally after #850 has been merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants