osquery / osquery-go

Go bindings for osquery
MIT License
388 stars 79 forks source link

wait until socket is available #50

Closed groob closed 6 years ago

groob commented 6 years ago

From @theopolis in slack:

I’m seriousness, yes, there is lag between socket creation and socket availability. Your thrift wrapper should take care of this, C++ and python do it by waiting up to —timeout seconds, and retrying every 200ms

leonjza commented 6 years ago

For now, I handle this with a small loop:

for count < tries {

    if _, err := os.Stat(*socketPath); os.IsNotExist(err) {

        time.Sleep(time.Millisecond * 200)
        count++

        continue
    }
}
groob commented 6 years ago

This should really be fixed upstream by thrift since it asks for a timeout... https://github.com/kolide/osquery-go/blob/dc07ffdf186374c0a1328bb181e5f11d854508a2/transport/transport.go#L21

groob commented 6 years ago

Digging further it appears that timeout is propagated all the way to stdlib net.DialTimeout but it still fails: https://github.com/apache/thrift/blob/d907cc92db5b93e699a4282e979d097ea863215a/lib/go/thrift/socket.go#L97

theopolis commented 6 years ago

Thanks for this!

That timeout (Open) is a time waiting for socket response. Our libraries should be implementing a timeout/retry check for the initial open as we race against the OS to make the socket available.