Skip to content

Commit ef7f363

Browse files
mnenciaarmru
andauthored
fix(bootstrap): start all log pipes during WithActiveInstance (#10043)
WithActiveInstance is used during bootstrap (Job-based initdb, join, restore) to temporarily start postgres. Previously it only started the CSV log pipe, but there are three named pipes that need consumers: postgres (raw) and postgres.csv are written by postgres, while postgres.json is written by other components such as the archive/restore command implementation. Without the corresponding pipe readers running, the FIFO files are never created. Postgres or other components then create regular files at those paths, and log output from non-CSV pipes during bootstrap is lost. Start all three log pipe readers (CSV, raw, JSON) matching the behavior of runSubCommand. Closes #10042 Signed-off-by: Marco Nenciarini <[email protected]> Signed-off-by: Armando Ruocco <[email protected]> Co-authored-by: Armando Ruocco <[email protected]>
1 parent 519f8f3 commit ef7f363

1 file changed

Lines changed: 27 additions & 3 deletions

File tree

‎pkg/management/postgres/instance.go‎

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -921,19 +921,43 @@ func setExtensionEnvVars(extensionList []apiv1.ExtensionConfiguration, envMap en
921921
// WithActiveInstance execute the internal function while this
922922
// PostgreSQL instance is running
923923
func (instance *Instance) WithActiveInstance(inner func() error) error {
924-
// Start the CSV logpipe to redirect log to stdout
924+
// Start all log pipe readers so the FIFOs are created before postgres or other
925+
// components (e.g. the archive/restore command implementation) try to write logs.
926+
// Without these readers nothing calls Mkfifo on the log paths, the writers fall
927+
// back to creating regular files, and their log output is silently lost.
925928
ctx, ctxCancel := context.WithCancel(context.Background())
926-
csvPipe := logpipe.NewLogPipe()
927929

930+
csvPipe := logpipe.NewLogPipe()
928931
go func() {
929932
if err := csvPipe.Start(ctx); err != nil {
930-
log.Info("csv pipeline encountered an error", "err", err)
933+
log.Info("csv log pipe encountered an error", "err", err)
934+
}
935+
}()
936+
937+
rawPipe := logpipe.NewRawLineLogPipe(
938+
filepath.Join(postgres.LogPath, postgres.LogFileName),
939+
logpipe.LoggingCollectorRecordName,
940+
)
941+
go func() {
942+
if err := rawPipe.Start(ctx); err != nil {
943+
log.Info("raw log pipe encountered an error", "err", err)
944+
}
945+
}()
946+
947+
jsonPipe := logpipe.NewJSONLineLogPipe(
948+
filepath.Join(postgres.LogPath, postgres.LogFileName+".json"),
949+
)
950+
go func() {
951+
if err := jsonPipe.Start(ctx); err != nil {
952+
log.Info("json log pipe encountered an error", "err", err)
931953
}
932954
}()
933955

934956
defer func() {
935957
ctxCancel()
936958
csvPipe.GetExitedCondition().Wait()
959+
rawPipe.GetExitedCondition().Wait()
960+
jsonPipe.GetExitedCondition().Wait()
937961
}()
938962

939963
err := instance.Startup()

0 commit comments

Comments
 (0)