fix consume fail
This commit is contained in:
@@ -269,10 +269,21 @@ func newEventBusCommand() *cobra.Command {
|
||||
ctx, cancel := signal.NotifyContext(c.Context(), os.Interrupt, syscall.SIGTERM)
|
||||
defer cancel()
|
||||
|
||||
// Acquire ReadyPipe early so pre-bus.Run failures can signal
|
||||
// 'E' to the parent process instead of silently dying.
|
||||
readyPipe := busctl.ReadyFDFromEnv()
|
||||
failEarly := func(err error) error {
|
||||
if readyPipe != nil {
|
||||
_, _ = readyPipe.Write([]byte{'E'})
|
||||
_ = readyPipe.Close()
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
configDir := defaultConfigDir()
|
||||
resolvedID, secret, _, _, err := authpkg.ResolveAppCredentialsStrict(configDir)
|
||||
if err != nil {
|
||||
return fmt.Errorf("event _bus: %w", err)
|
||||
return failEarly(fmt.Errorf("event _bus: %w", err))
|
||||
}
|
||||
clientID := resolvedID
|
||||
if clientIDOverride != "" {
|
||||
@@ -288,7 +299,7 @@ func newEventBusCommand() *cobra.Command {
|
||||
ClientSecret: secret,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
return failEarly(err)
|
||||
}
|
||||
|
||||
// busLogger writes to bus.log inside WorkDir so the daemon's
|
||||
@@ -310,7 +321,7 @@ func newEventBusCommand() *cobra.Command {
|
||||
Edition: editionName,
|
||||
Source: src,
|
||||
IdleTimeout: idleTimeout,
|
||||
ReadyPipe: busctl.ReadyFDFromEnv(),
|
||||
ReadyPipe: readyPipe,
|
||||
Logger: slog.Default(),
|
||||
}
|
||||
// env-var tuning (only fills in fields left at zero; explicit
|
||||
|
||||
@@ -82,16 +82,17 @@ func itoa(n int64) string {
|
||||
}
|
||||
|
||||
// ClientIDHash returns the path-safe identifier derived from the (possibly
|
||||
// unsafe) ClientID string. We use sha256(clientID)[:16] hex-encoded; this is
|
||||
// the value placed in filesystem paths and Named Pipe names. The original
|
||||
// ClientID is stored in bus.meta and shown in status output. See plan
|
||||
// "路径安全" decision in §1.
|
||||
// unsafe) ClientID string. We use sha256(clientID)[:8] hex-encoded (16 chars);
|
||||
// this is the value placed in filesystem paths and Named Pipe names. 8 bytes
|
||||
// (64 bits) is sufficient to distinguish a handful of ClientIDs on one machine
|
||||
// while keeping the Unix socket path under macOS's 104-byte sun_path limit.
|
||||
// The original ClientID is stored in bus.meta and shown in status output.
|
||||
func ClientIDHash(clientID string) string {
|
||||
if clientID == "" {
|
||||
return ""
|
||||
}
|
||||
h := sha256.Sum256([]byte(clientID))
|
||||
return hex.EncodeToString(h[:16])
|
||||
return hex.EncodeToString(h[:8])
|
||||
}
|
||||
|
||||
// RedactSecret returns a redacted form of a secret string for logging and
|
||||
|
||||
@@ -60,7 +60,7 @@ func TestRawEvent_DedupKey_NilSafe(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestClientIDHash_StableAndPathSafe(t *testing.T) {
|
||||
pathSafe := regexp.MustCompile(`^[0-9a-f]{32}$`)
|
||||
pathSafe := regexp.MustCompile(`^[0-9a-f]{16}$`)
|
||||
cases := []string{
|
||||
"ding_abc123",
|
||||
"ding_with_special!@#",
|
||||
@@ -72,7 +72,7 @@ func TestClientIDHash_StableAndPathSafe(t *testing.T) {
|
||||
for _, in := range cases {
|
||||
got := ClientIDHash(in)
|
||||
if !pathSafe.MatchString(got) {
|
||||
t.Fatalf("ClientIDHash(%q) = %q, not path-safe hex16(32 chars)", in, got)
|
||||
t.Fatalf("ClientIDHash(%q) = %q, not path-safe hex8(16 chars)", in, got)
|
||||
}
|
||||
// Stable
|
||||
if got2 := ClientIDHash(in); got2 != got {
|
||||
|
||||
Reference in New Issue
Block a user