The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu
Go agent-ai-cliagent-harnessesagent-securitybrowser-extensionciclaude-codecloudcodexcursordetection-engineeringjevknowledge-basememorymobile-device-managementobservabilitysecuritysecurity-information-and-event-managementsecurity-toolstelemetrytraces
beacon_ingest: on Windows, wait out only a taken pipe name
Claude3d858ac24aa2
diff --git a/collector-builder/exporter/beaconjsonexporter/beaconingestextension/extension.go b/collector-builder/exporter/beaconjsonexporter/beaconingestextension/extension.goindex e4d89a87..ed256e9d 100644--- a/collector-builder/exporter/beaconjsonexporter/beaconingestextension/extension.go+++ b/collector-builder/exporter/beaconjsonexporter/beaconingestextension/extension.go@@ -39,7 +39,7 @@ type ingest struct {mu sync.Mutexserver *localingest.Serverdone chan error- // stopRetry and retried are set while Start is still waiting to listen (see listenRetries).+ // stopRetry and retried are set while Start is still waiting to listen (see retryableListenError).stopRetry chan struct{}retried chan struct{}}@@ -65,8 +65,9 @@ func newIngest(cfg *Config, logger *zap.Logger) *ingest {//// On Windows the pipe's name is in a namespace every account can create in, so an account that// takes it first must not be able to keep the whole collector down (the beaconjson exporter and the-// OTLP receivers with it). There a failed listen is reported as a recoverable error and retried-// every listenRetryInterval until it succeeds or the collector stops; meanwhile hooks refuse the+// OTLP receivers with it). There a listen that failed because the name is taken is reported as a+// recoverable error and retried every listenRetryInterval until it succeeds or the collector stops+// (any other listen error still fails the start); meanwhile hooks refuse the// impostor's pipe, which is not owned by SYSTEM or Administrators, and spool their events.func (e *ingest) Start(_ context.Context, host component.Host) error {if !asymptoteobserve.RuntimeLogAccessRestricted(e.cfg.LogPath) {@@ -80,8 +81,9 @@ func (e *ingest) Start(_ context.Context, host component.Host) error {e.serve(host, l)return nil}+ retryable := retryableListenError(err)err = fmt.Errorf("beacon_ingest: listen on %s: %w", e.socketPath(), err)- if !listenRetries {+ if !retryable {return err}e.logger.Error("beacon_ingest cannot listen yet; hooks spool their events until it can", zap.Error(err))@@ -96,11 +98,16 @@ func (e *ingest) Start(_ context.Context, host component.Host) error {return nil}+// listenRetryLogEvery is how many failed retries pass between warnings: about a minute at the+// default interval.+const listenRetryLogEvery = 12+// retryListen listens again every listenRetryInterval until it succeeds or stop is closed.func (e *ingest) retryListen(host component.Host, stop <-chan struct{}, retried chan<- struct{}) {defer close(retried)ticker := time.NewTicker(listenRetryInterval)defer ticker.Stop()+ failures := 0for {select {case <-stop:@@ -109,6 +116,10 @@ func (e *ingest) retryListen(host component.Host, stop <-chan struct{}, retried}l, err := e.listen(e.socketPath())if err != nil {+ // Once a minute or so, so a long wait stays visible without filling the log.+ if failures++; failures%listenRetryLogEvery == 0 {+ e.logger.Warn("beacon_ingest still cannot listen", zap.Error(err), zap.Int("attempts", failures))+ }continue}e.serve(host, l)diff --git a/collector-builder/exporter/beaconjsonexporter/beaconingestextension/extension_windows_test.go b/collector-builder/exporter/beaconjsonexporter/beaconingestextension/extension_windows_test.goindex 5a61fd5f..2d7ccfcc 100644--- a/collector-builder/exporter/beaconjsonexporter/beaconingestextension/extension_windows_test.go+++ b/collector-builder/exporter/beaconjsonexporter/beaconingestextension/extension_windows_test.go@@ -221,3 +221,16 @@ func TestValidWindowsName(t *testing.T) {}}}++// Only a taken name is waited out. A socket_path that can never be a pipe fails the start loudly,+// as it did before, instead of a collector that looks healthy and never serves.+func TestAListenErrorThatCannotClearStillFailsTheStart(t *testing.T) {+ cfg := createDefaultConfig()+ cfg.SocketPath = `C:\ProgramData\Beacon\ingest.sock`+ cfg.LogPath = filepath.Join(t.TempDir(), "logs", "runtime.jsonl")+ ext := newIngest(cfg, zap.NewNop())+ if err := ext.Start(context.Background(), nil); err == nil {+ _ = ext.Shutdown(context.Background())+ t.Fatal("Start succeeded on a socket_path that is not a named pipe")+ }+}diff --git a/collector-builder/exporter/beaconjsonexporter/beaconingestextension/listen_unix.go b/collector-builder/exporter/beaconjsonexporter/beaconingestextension/listen_unix.goindex d43d8df8..cddc8f7c 100644--- a/collector-builder/exporter/beaconjsonexporter/beaconingestextension/listen_unix.go+++ b/collector-builder/exporter/beaconjsonexporter/beaconingestextension/listen_unix.go@@ -4,8 +4,8 @@ package beaconingestextensionimport "time"-// listenRetries is false on Unix: the socket's directory belongs to root, so a failed listen is a-// real conflict to surface (see Start), not a name someone else took first.-const listenRetries = false+// retryableListenError is always false on Unix: the socket's directory belongs to root, so a failed+// listen is a real conflict to surface (see Start), not a name someone else took first.+func retryableListenError(error) bool { return false }var listenRetryInterval = 5 * time.Seconddiff --git a/collector-builder/exporter/beaconjsonexporter/beaconingestextension/listen_windows.go b/collector-builder/exporter/beaconjsonexporter/beaconingestextension/listen_windows.goindex 71d2d5b3..468734ee 100644--- a/collector-builder/exporter/beaconjsonexporter/beaconingestextension/listen_windows.go+++ b/collector-builder/exporter/beaconjsonexporter/beaconingestextension/listen_windows.go@@ -2,11 +2,22 @@package beaconingestextension-import "time"+import (+ "errors"+ "io/fs"+ "time"-// listenRetries is true on Windows, where any account can create the pipe's name first (see Start).-const listenRetries = true+ "golang.org/x/sys/windows"+)-// listenRetryInterval is how often a collector that could not create its pipe tries again; tests-// shorten it.+// retryableListenError reports whether a failed listen is the pipe's name being held by someone+// else, which any account can do on Windows (see Start) and which clears when they let go. Anything+// else -- a socket_path that is not a pipe path, a bad security descriptor -- never clears, so it+// fails the start as before.+func retryableListenError(err error) bool {+ return errors.Is(err, windows.ERROR_ACCESS_DENIED) || errors.Is(err, windows.ERROR_PIPE_BUSY) || errors.Is(err, fs.ErrExist)+}++// listenRetryInterval is how often a collector whose pipe name is taken tries again; tests shorten+// it.var listenRetryInterval = 5 * time.Second