Remote WMI Calls in Golang breaks "randomly"

0

I have to make some remote WMI queries from our Golang tools.

Currently, I use the https://github.com/StackExchange/wmi package for WMI calls. This, in turn, is based on the OLE calls by https://github.com/go-ole/go-ole.

Basically, the approach works very well and with high performance. We make several hundred calls per hour.

For example, our code looks like this:

package main

import (
    "log"
    "github.com/StackExchange/wmi"
)

type Win32_PerfRawData_PerfOS_Processor struct {
    PercentProcessorTime uint64
    TimeStamp_Sys100NS   uint64
}

func main() {

    var rawOS []Win32_PerfRawData_PerfOS_Processor
    err := wmi.Query("SELECT * FROM Win32_PerfRawData_PerfOS_Processor where name='_Total'", &rawOS, "remotehost")
    if err != nil {
        log.Fatal(err)
    }

    // here comes stuff to work with rawOS... 

}

Unfortunately, it happens from time to time that something goes completely wrong. And our Golang Tool breaks completely and we run into an exception:

Exception 0xc0000005 0x0 0xffffffffffffffff 0x7ffadcc72503
PC=0x7ffadcc72503
signal arrived during external code execution
syscall.Syscall(0x7ffad9f0c0a0, 0x1, 0xc0019dbce0, 0x0, 0x0, 0x0, 0x0, 0x0)
        c:/go/src/runtime/**syscall_windows.go:188** +0xfa
golang.org/x/sys/windows.(*Proc).Call(0xc00066e760, 0xc000adc448, 0x1, 0x1, 0x8, 0x9273a0, 0xa63c01, 0xc000adc448)
        C:/goworkspace/src/golang.org/x/sys/windows/dll_windows.go:139 +0x136
golang.org/x/sys/windows.(*LazyProc).Call(0xc00026d080, 0xc000adc448, 0x1, 0x1, 0x0, 0xc001e93980, 0x4317b8, 0x9eb018)
        C:/goworkspace/src/golang.org/x/sys/windows/dll_windows.go:317 +0x66
github.com/go-ole/go-ole.VariantClear(0xc0019dbce0, 0xc001e93bc8, 0xc001e93990)
        C:/goworkspace/src/github.com/go-ole/go-ole/com.go:248 +0x6c
github.com/go-ole/go-ole.(*VARIANT).Clear(0xc0019dbce0, 0x0, 0x0)
        C:/goworkspace/src/github.com/go-ole/go-ole/variant.go:47 +0x32
main.(*Client).Query(0xdc5ed0, 0x9dd17d, 0x30, 0x90b540, 0xc0012d7760, 0xc0012d7780, 0x2, 0x2, 0x0, 0x0)
        C:/goworkspace/src/github.com/StackExchange/wmi/wmi.go:211 +0x939
main.Query(0x9dd17d, 0x30, 0x90b540, 0xc0012d7760, 0xc0012d7780, 0x2, 0x2, 0x0, 0x0)
        C:/goworkspace/src/github.com/StackExchange/wmi/wmi.go:52 +0x10c
main.GetWMIProcess(0xc00004d180, 0xc000273380, 0xc022e21590, 0x11ae7b33b1a684)
        C:/goworkspace/src/xxx/1.go:69 +0x234
main.(*Server).startupServer.func10(0xc00004d180, 0xc000273380)
        C:/goworkspace/src/xxx/2.go:216 +0x3c
main.taskloop(0xc000273380)
        C:/goworkspace/src/xxx/3.go:60 +0x206
created by main.(*ServerTask).Start
        C:/goworkspace/src/xxx/3.go:30 +0xbb

We have this exception from time to time in various WMI queries. The pattern behind it is that it usually occurs at night, when the remote servers either process massive batches or are backed up etc. But it also occurred during the day.

Since we have not yet found a way to catch the exception, my question is:

What are we doing "wrong"? The query breaks directly. The error does not come out of it. In the end is the last thing we always see: syscall_windows.go:188.

Of course, we have also tested what happens if the remote server is not reachable. This can be easily handled: "2020/03/20 10:53:53 Exception occurred. (The RPC server is unavailable. )".

So, our questions are:

  • Does anyone use the above packages for remote WMI queries? Any comments or advice? Best Practices?
  • Are we basically doing something wrong in the code? And, why does it work most of the time?
  • Does anyone have an alternative way for remote WMI calls in Golang?

Any help would be much appreciated.

go
wmi
asked on Stack Overflow May 20, 2020 by Doxa • edited May 20, 2020 by Doxa

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0