mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-02-21 12:16:36 +00:00
terminal_services: refactor collector (#1729)
This commit is contained in:
@@ -5,8 +5,10 @@ package mi
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"reflect"
|
||||
"sync"
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
@@ -14,6 +16,10 @@ import (
|
||||
|
||||
// We have to registry a global callback function, since the amount of callbacks is limited.
|
||||
var operationUnmarshalCallbacksInstanceResult = sync.OnceValue[uintptr](func() uintptr {
|
||||
// Workaround for a deadlock issue in go.
|
||||
// Ref: https://github.com/golang/go/issues/55015
|
||||
go time.Sleep(time.Duration(math.MaxInt64))
|
||||
|
||||
return windows.NewCallback(func(
|
||||
operation *Operation,
|
||||
callbacks *OperationUnmarshalCallbacks,
|
||||
|
||||
@@ -212,9 +212,16 @@ func (s *Session) QueryUnmarshal(dst any,
|
||||
|
||||
errs := make([]error, 0)
|
||||
|
||||
for err := range errCh {
|
||||
if err != nil {
|
||||
// We need an active go routine to prevent a
|
||||
// fatal error: all goroutines are asleep - deadlock!
|
||||
// ref: https://github.com/golang/go/issues/55015
|
||||
// go time.Sleep(5 * time.Second)
|
||||
|
||||
for {
|
||||
if err, ok := <-errCh; err != nil {
|
||||
errs = append(errs, err)
|
||||
} else if !ok {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user