Skip to content

Commit b20ffb4

Browse files
run in transaction and fix test
1 parent 54e8a1f commit b20ffb4

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

flow/connectors/postgres/pgdump_schema.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,16 @@ func buildPsqlArgs(config *protos.PostgresConfig) []string {
152152
"-h", config.Host,
153153
"-p", strconv.FormatUint(uint64(port), 10),
154154
"-d", config.Database,
155+
// Wrap the entire dump in a single transaction so partial failures
156+
// roll back cleanly (makes the activity safely retryable) and avoid
157+
// per-statement autocommit overhead on high-latency links.
158+
"--single-transaction",
159+
// Without this, psql logs errors to stderr but exits 0, so a half-
160+
// applied schema would be reported as success. ON_ERROR_STOP=1 makes
161+
// psql exit non-zero on the first failed statement.
162+
"-v", "ON_ERROR_STOP=1",
163+
// Quiet informational chatter; errors still go to stderr.
164+
"--quiet",
155165
}
156166
if config.User != "" {
157167
args = append(args, "-U", config.User)

flow/connectors/postgres/pgdump_schema_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,13 @@ func TestRunPipeline_ContextCancel(t *testing.T) {
205205
requireUnix(t)
206206
ctx, cancel := context.WithCancel(t.Context())
207207

208-
// long-running src that ignores stdin
209-
src := exec.CommandContext(ctx, "sh", "-c", "sleep 30")
208+
// Use exec'd binaries directly (not `sh -c "..."`). When sh is run with
209+
// a single argument, many shells fork a child for the command rather than
210+
// exec-replacing themselves. That child inherits sh's stderr fd, and Go's
211+
// exec.Wait blocks draining stderr until every fd holder closes it -- so
212+
// CommandContext killing sh isn't enough; the child keeps stderr open and
213+
// Wait hangs. Using a single-process command avoids the inheritance.
214+
src := exec.CommandContext(ctx, "sleep", "30")
210215
dst := exec.CommandContext(ctx, "cat")
211216
dst.Stdout = &bytes.Buffer{}
212217

0 commit comments

Comments
 (0)