Skip to content

Add configurable Postgres replication socket timeout#715

Open
sravan27 wants to merge 1 commit into
powersync-ja:mainfrom
sravan27:sravan/postgres-half-open-replication-proof
Open

Add configurable Postgres replication socket timeout#715
sravan27 wants to merge 1 commit into
powersync-ja:mainfrom
sravan27:sravan/postgres-half-open-replication-proof

Conversation

@sravan27

@sravan27 sravan27 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds an optional Postgres replication_socket_timeout setting that applies only to logical replication connections.

This is a narrow follow-up to #700. The issue discussion established that half-open source connections can leave replication stalled for 12-16 minutes before the OS/TCP path surfaces an error. @powersync/service-jpgwire already destroys sockets on timeout and the replication job already reconnects when WalStream.replicate() throws, but the Postgres replication connection had no per-stream override comparable to the existing snapshot timeout.

With this change, self-hosted operators can choose a shorter timeout for the replication socket so a half-open stream is destroyed earlier and the existing retry path can reconnect.

Details

  • Adds replication_socket_timeout to the Postgres data source config.
  • Normalizes the value from seconds to milliseconds.
  • Applies the timeout only in PgManager.replicationConnection().
  • Leaves the default behavior unchanged when the option is omitted.
  • Keeps snapshot connection behavior unchanged.

Example:

replication:
  connections:
    - type: postgresql
      uri: postgresql://...
      replication_socket_timeout: 90

Tests

  • pnpm --filter @powersync/service-module-postgres build
  • pnpm --filter @powersync/service-module-postgres build:tests
  • pnpm exec vitest run test/src/config.test.ts from modules/module-postgres

Scope

This does not attempt to solve every option discussed in #700. In particular, it does not add TCP_USER_TIMEOUT, TCP_KEEPINTVL, TCP_KEEPCNT, or a new replication-progress health model. It is a small operational knob that lets affected deployments reduce the current detection window using the socket-timeout behavior already present in service-jpgwire.

@changeset-bot

changeset-bot Bot commented Jul 9, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7b6e7df

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 12 packages
Name Type
@powersync/service-module-postgres Patch
@powersync/service-schema Patch
@powersync/service-image Patch
@powersync/service-core Patch
@powersync/service-module-convex Patch
@powersync/service-module-core Patch
@powersync/service-module-mongodb-storage Patch
@powersync/service-module-mongodb Patch
@powersync/service-module-mssql Patch
@powersync/service-module-mysql Patch
@powersync/service-module-postgres-storage Patch
test-client Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant