Repository navigation
feat(sync-service): Terminate shape consumer processes after timeout #3455
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
magnetised
merged 7 commits into
main
from
magnetised/issue-3253-suspend-consumers-after-timeout
Nov 20, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d498372
feat(sync-service): Terminate shape consumer processes after timeout
magnetised ba61ce1
Add env var to toggle suspend behaviour
magnetised a447749
simplify e2e test
magnetised a9cd8ef
add missing receive
magnetised eb69206
[review] revert write_concurrency
magnetised fa9b258
add consumer suspend to feature flags
magnetised 7d4d7f3
fix rebase
magnetised File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@core/sync-service': patch | ||
| --- | ||
|
|
||
| Reduce memory usage by terminating consumer processes after the hibernation timeout |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| [doc Verify that consumer processes suspend and resume correctly] | ||
|
|
||
| [include _macros.luxinc] | ||
|
|
||
| [global pg_container_name=consumer-suspend-resume__pg] | ||
|
|
||
| ### | ||
|
|
||
| [invoke setup_pg] | ||
|
|
||
| # Create a table for subsequent shape requests | ||
| [invoke start_psql] | ||
|
|
||
| [shell psql] | ||
| !create table items(val text); | ||
| ??CREATE | ||
|
|
||
| !insert into items values ('1'), ('2'); | ||
| ??INSERT | ||
|
|
||
| # Start Electric and wait for it to finish initialization. | ||
| # Set a very small hibernation timeout so consumers will shutdown quickly | ||
| [invoke setup_electric_with_env "ELECTRIC_SHAPE_HIBERNATE_AFTER=200ms ELECTRIC_SHAPE_SUSPEND_CONSUMER=true ELECTRIC_FEATURE_FLAGS=suspend_consumers"] | ||
| [shell electric] | ||
| [timeout 10] | ||
| ??[debug] Replication client started streaming | ||
|
|
||
| # Start a live shape request | ||
| [shell client] | ||
| [invoke curl_shape "http://localhost:3000/v1/shape?table=items&offset=-1"] | ||
|
|
||
| ??HTTP/1.1 200 OK | ||
|
|
||
| ?electric-handle: ([\d-]+) | ||
| [global handle=$1] | ||
|
|
||
| ??electric-offset: 0_0 | ||
|
|
||
| ??[{"headers":{"operation":"insert","relation":["public","items"]},"key":"\"public\".\"items\"/\"1\"","value":{"val":"1"}},\ | ||
| {"headers":{"operation":"insert","relation":["public","items"]},"key":"\"public\".\"items\"/\"2\"","value":{"val":"2"}},\ | ||
| {"headers":{"control":"snapshot-end" | ||
|
|
||
| [invoke curl_shape "http://localhost:3000/v1/shape?table=items&handle=$handle&offset=0_0&live"] | ||
|
|
||
| # Check that the consumer process for the given handle has suspended itself | ||
| [shell electric] | ||
| [sleep 1] | ||
|
|
||
| ??[debug] Suspending consumer $handle | ||
| !{:active_consumer_count, Electric.Shapes.ConsumerRegistry.active_consumer_count("single_stack")} | ||
| ?{:active_consumer_count, 0} | ||
|
|
||
| # Verify that writes to the handle re-create the consumer process | ||
| [shell psql] | ||
| !insert into items values ('3'); | ||
| ??INSERT | ||
|
|
||
|
|
||
| [shell electric] | ||
| ??[info] Started consumer for existing handle $handle | ||
| !{:active_consumer_count, Electric.Shapes.ConsumerRegistry.active_consumer_count("single_stack")} | ||
| ?{:active_consumer_count, 1} | ||
|
|
||
| [shell client] | ||
| [timeout 1] | ||
|
|
||
| ??HTTP/1.1 200 | ||
|
|
||
| ??transfer-encoding: chunked | ||
| ?electric-offset: ([0-9]+)_0 | ||
| [local global_last_seen_lsn=$1] | ||
|
|
||
| ??"headers":{"last":true,"lsn":"$global_last_seen_lsn","op_position":0,"operation":"insert","relation":["public","items"],"txids": | ||
| ??"key":"\"public\".\"items\"/\"3\"","value":{"val":"3"} | ||
| ??"headers":{"control":"up-to-date","global_last_seen_lsn":"$global_last_seen_lsn"} | ||
|
|
||
|
|
||
| [cleanup] | ||
| [invoke teardown] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.