Skip to content

Commit aa0449f

Browse files
committed
fix(envd): suppress repeat MMDS poll failures
The MMDS poll runs on a 50ms ticker and was writing one stderr line per failed iteration, which 1:1-amplified into journald during outages (e.g. before MMDS is up at boot). Log only the first failure of each kind and tag stderr writes as syslog WARNING (<4>). Drop the context-cancelled stderr line: shutdown noise.
1 parent dbef5ef commit aa0449f

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

packages/envd/internal/host/mmds.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,26 +139,32 @@ func PollForMMDSOpts(ctx context.Context, mmdsChan chan<- *MMDSOpts, envVars *ut
139139
httpClient := &http.Client{}
140140
defer httpClient.CloseIdleConnections()
141141

142+
var lastErr error
143+
142144
ticker := time.NewTicker(50 * time.Millisecond)
143145
defer ticker.Stop()
144146

145147
for {
146148
select {
147149
case <-ctx.Done():
148-
fmt.Fprintf(os.Stderr, "context cancelled while waiting for mmds opts")
150+
if lastErr != nil {
151+
fmt.Fprintf(os.Stderr, "<4>gave up polling for mmds opts: %v (last error: %v)\n", ctx.Err(), lastErr)
152+
} else {
153+
fmt.Fprintf(os.Stderr, "<4>gave up polling for mmds opts: %v\n", ctx.Err())
154+
}
149155

150156
return
151157
case <-ticker.C:
152158
token, err := getMMDSToken(ctx, httpClient)
153159
if err != nil {
154-
fmt.Fprintf(os.Stderr, "error getting mmds token: %v\n", err)
160+
lastErr = fmt.Errorf("get mmds token: %w", err)
155161

156162
continue
157163
}
158164

159165
mmdsOpts, err := getMMDSOpts(ctx, httpClient, token)
160166
if err != nil {
161-
fmt.Fprintf(os.Stderr, "error getting mmds opts: %v\n", err)
167+
lastErr = fmt.Errorf("get mmds opts: %w", err)
162168

163169
continue
164170
}

0 commit comments

Comments
 (0)