From 9d5e155ff30cda8120ea569dde3a5ccaba17fb05 Mon Sep 17 00:00:00 2001 From: aaron-congo Date: Wed, 4 Nov 2026 16:51:32 -0700 Subject: [PATCH 1/3] docs-v1.1.0 (ruby): document Blue/Green blue-connection invalidation and MySQL timeout failover - Blue/Green: add bg_drop_blue_connections to the parameters, the phase list, and the planned-maintenance scenario note. - Enhanced failover: document that mysql2 and trilogy fail over on read_timeout, wait_timeout disconnects (4031), and lost connections, with guidance on read_timeout and idle pooled connections. - Development guide: storage service reads publish a DataAccessEvent only with register_access: true. --- content/dev-guide.yaml | 7 ++-- content/failover.yaml | 38 +++++++++++++++++++ content/plugins.yaml | 6 +++ content/scenarios.yaml | 1 + .../development-guide/service-container.md | 7 ++-- site/docs-ruby/enhanced-failover.md | 38 +++++++++++++++++++ site/docs-ruby/using-plugins/blue-green.md | 2 + site/src/generated/scenarios-ruby.json | 1 + 8 files changed, 94 insertions(+), 6 deletions(-) diff --git a/content/dev-guide.yaml b/content/dev-guide.yaml index 93b7c05..a418db7 100644 --- a/content/dev-guide.yaml +++ b/content/dev-guide.yaml @@ -302,9 +302,10 @@ wrappers: - `exists?(name, key)` / `remove(name, key)` / `clear(name)` / `clear_all`. whenToUse: | Use it to cache data reused across the wrapper — for example the - `RdsHostListProvider` caches cluster topology here. Reads publish a - `DataAccessEvent` (unless `register_access: false`), which keeps related - monitors alive. + `RdsHostListProvider` caches cluster topology here. A read publishes a + `DataAccessEvent` only when called with `register_access: true`, which + extends the expiration of any monitor that produces that cache's data. Pass + it only when the read should keep that monitor alive. - name: "Monitor Service" short: "Monitor Service" global: true diff --git a/content/failover.yaml b/content/failover.yaml index 4800894..c6d6403 100644 --- a/content/failover.yaml +++ b/content/failover.yaml @@ -392,6 +392,44 @@ enhanced: wrapperOnly: ruby: + - | + ## Timeouts and idle connections on MySQL + + On MySQL, the failover plugin treats a connection that timed out or was closed by + the server as lost, and fails over. This applies to `mysql2` (`WrapperMysql2Client` + and `aws_mysql2`) and to `trilogy` (`WrapperTrilogyClient` and `aws_trilogy`), and + includes: + + - A query that runs longer than the client's `read_timeout`. The driver closes the + socket before it raises the timeout, so the connection cannot be reused. + - The first query on a connection that sat idle longer than the server's + `wait_timeout`. MySQL 8.0.24 and later closes such a connection and reports error + 4031. + - A connection lost during a query, or a server that has gone away (with `mysql2`, + errors 2006, 2013, and 2055). + + Your code then sees `FailoverSuccessError` (or `TransactionStateUnknownError` inside a + transaction) instead of the driver's timeout or connection error. Through ActiveRecord + these errors are re-raised unchanged (see [ActiveRecord integration](#activerecord-integration)), + and ActiveRecord does not retry them for you. To avoid a failover that is caused by a + slow query or an idle connection rather than by the database: + + - Set `read_timeout` higher than your slowest expected query. + - Keep pooled connections from outliving `wait_timeout`: raise `wait_timeout` on the + server, or have the pool close idle connections sooner, for example with + ActiveRecord's `idle_timeout`. + + A lock wait timeout (error 1205) does not trigger failover. The connection is still + healthy, and the driver's error is raised as usual. + + :::note Changed in 1.1.0 + Before 1.1.0, `mysql2` did not fail over on a `read_timeout` or on errors 4031 and + 2055. A `read_timeout` raised `Mysql2::Error::TimeoutError` (`ActiveRecord::AdapterTimeout` + under `aws_mysql2`), and errors 4031 and 2055 were raised as is + (`ActiveRecord::ConnectionFailed` under `aws_mysql2`, which ActiveRecord answered by + reconnecting to the original endpoint and retrying the queries it considers + retryable). + ::: - | ## ActiveRecord integration diff --git a/content/plugins.yaml b/content/plugins.yaml index aa2478e..3a55408 100644 --- a/content/plugins.yaml +++ b/content/plugins.yaml @@ -2185,6 +2185,7 @@ plugins: - **During the active switchover**, it temporarily suspends calls to blue nodes and substitutes hostnames with the corresponding IP addresses to avoid stale DNS. - **After the switchover**, it monitors DNS until blue endpoints are reconfigured, then stops substituting. - **Once switchover completes**, it rejects new connections to green nodes. + - **Once the switchover is confirmed**, it invalidates connections that were opened to the old blue environment before the switchover, so their next use raises an error instead of reading from retired blue nodes. See `bg_drop_blue_connections` below. - **If the switchover fails or rolls back**, it detects that and restores normal handling. code: ruby: bg @@ -2246,6 +2247,11 @@ plugins: description: "Maximum duration allowed for switchover completion. If the process stalls or exceeds this, the wrapper assumes completion and resumes normal operations." spellings: ruby: { name: bg_switchover_timeout_sec, type: float, required: "No", default: "180.0", unit: s, example: "180.0" } + - concept: dropBlueConnections + type: boolean + description: "Whether to invalidate connections that were opened to the old blue environment before a switchover. Once the switchover is confirmed (it reaches the `POST` or `COMPLETED` phase), each such connection is closed the next time it is used. With the failover plugin enabled, that use reconnects through Blue/Green routing and raises `FailoverSuccessError` (or `TransactionStateUnknownError` inside a transaction); without it, the driver raises its closed-connection error. Either way the application gets an explicit error instead of a stale read from the old blue environment. Connections are invalidated only if the plugin saw the switchover while it was in progress, and none are invalidated if the switchover rolls back." + spellings: + ruby: { name: bg_drop_blue_connections, required: "No", default: "true", example: "false" } monitoringPrefix: ruby: "bg_monitoring_" monitoringSnippet: diff --git a/content/scenarios.yaml b/content/scenarios.yaml index 62541a7..1c4faf7 100644 --- a/content/scenarios.yaml +++ b/content/scenarios.yaml @@ -578,6 +578,7 @@ addons: - "A Blue/Green Deployment exists and the wrapper can read its status before the switchover starts." notes: - "The plugin holds traffic during the switchover instead of letting it fail, then resumes against the promoted deployment." + - "After the switchover, connections that were opened to the old blue environment are closed the next time they are used. With the failover plugin (on by default), that use raises `FailoverSuccessError` (or `TransactionStateUnknownError` inside a transaction) on a connection that is already reconnected to the new environment, so handle it as you would a failover. Set `bg_drop_blue_connections: false` to keep using those connections instead." - "If you connect through an RDS Proxy, AWS requires the blue cluster to be registered with the proxy before the Blue/Green deployment is created — you cannot add the proxy afterward." links: [rds_bluegreen] diff --git a/site/docs-ruby/development-guide/service-container.md b/site/docs-ruby/development-guide/service-container.md index f687f0f..11e7f86 100644 --- a/site/docs-ruby/development-guide/service-container.md +++ b/site/docs-ruby/development-guide/service-container.md @@ -155,9 +155,10 @@ background cleanup thread. Shared across the wrapper. **When to use it** Use it to cache data reused across the wrapper — for example the -`RdsHostListProvider` caches cluster topology here. Reads publish a -`DataAccessEvent` (unless `register_access: false`), which keeps related -monitors alive. +`RdsHostListProvider` caches cluster topology here. A read publishes a +`DataAccessEvent` only when called with `register_access: true`, which +extends the expiration of any monitor that produces that cache's data. Pass +it only when the read should keep that monitor alive. ### Monitor Service diff --git a/site/docs-ruby/enhanced-failover.md b/site/docs-ruby/enhanced-failover.md index d3e2b57..e36c96e 100644 --- a/site/docs-ruby/enhanced-failover.md +++ b/site/docs-ruby/enhanced-failover.md @@ -231,6 +231,44 @@ discarding it, so you should not call `disconnect!` or discard the connection ob yourself — the pool already holds the live, reconnected connection. ::: +## Timeouts and idle connections on MySQL + +On MySQL, the failover plugin treats a connection that timed out or was closed by +the server as lost, and fails over. This applies to `mysql2` (`WrapperMysql2Client` +and `aws_mysql2`) and to `trilogy` (`WrapperTrilogyClient` and `aws_trilogy`), and +includes: + +- A query that runs longer than the client's `read_timeout`. The driver closes the + socket before it raises the timeout, so the connection cannot be reused. +- The first query on a connection that sat idle longer than the server's + `wait_timeout`. MySQL 8.0.24 and later closes such a connection and reports error + 4031. +- A connection lost during a query, or a server that has gone away (with `mysql2`, + errors 2006, 2013, and 2055). + +Your code then sees `FailoverSuccessError` (or `TransactionStateUnknownError` inside a +transaction) instead of the driver's timeout or connection error. Through ActiveRecord +these errors are re-raised unchanged (see [ActiveRecord integration](#activerecord-integration)), +and ActiveRecord does not retry them for you. To avoid a failover that is caused by a +slow query or an idle connection rather than by the database: + +- Set `read_timeout` higher than your slowest expected query. +- Keep pooled connections from outliving `wait_timeout`: raise `wait_timeout` on the + server, or have the pool close idle connections sooner, for example with + ActiveRecord's `idle_timeout`. + +A lock wait timeout (error 1205) does not trigger failover. The connection is still +healthy, and the driver's error is raised as usual. + +:::note Changed in 1.1.0 +Before 1.1.0, `mysql2` did not fail over on a `read_timeout` or on errors 4031 and +2055. A `read_timeout` raised `Mysql2::Error::TimeoutError` (`ActiveRecord::AdapterTimeout` +under `aws_mysql2`), and errors 4031 and 2055 were raised as is +(`ActiveRecord::ConnectionFailed` under `aws_mysql2`, which ActiveRecord answered by +reconnecting to the original endpoint and retrying the queries it considers +retryable). +::: + ## ActiveRecord integration When using the wrapper through ActiveRecord (`aws_postgresql` or `aws_mysql2`), the diff --git a/site/docs-ruby/using-plugins/blue-green.md b/site/docs-ruby/using-plugins/blue-green.md index 9c3b027..d5941cb 100644 --- a/site/docs-ruby/using-plugins/blue-green.md +++ b/site/docs-ruby/using-plugins/blue-green.md @@ -18,6 +18,7 @@ switchover status and adjusting connection handling at each phase: - **During the active switchover**, it temporarily suspends calls to blue nodes and substitutes hostnames with the corresponding IP addresses to avoid stale DNS. - **After the switchover**, it monitors DNS until blue endpoints are reconfigured, then stops substituting. - **Once switchover completes**, it rejects new connections to green nodes. +- **Once the switchover is confirmed**, it invalidates connections that were opened to the old blue environment before the switchover, so their next use raises an error instead of reading from retired blue nodes. See `bg_drop_blue_connections` below. - **If the switchover fails or rolls back**, it detects that and restores normal handling. @@ -92,6 +93,7 @@ Verify plugin compatibility within your Ruby configuration using the [compatibil | `bg_increased_sec` | Float | No | `1.0` | Increased interval for checking Blue/Green Deployment status. Configure within 0.5–2 sec. *(sec)*

Example: `1.0` | | `bg_high_sec` | Float | No | `0.1` | High-frequency interval for checking Blue/Green Deployment status. Configure within 0.05–0.5 sec. *(sec)*

Example: `0.1` | | `bg_switchover_timeout_sec` | Float | No | `180.0` | Maximum duration allowed for switchover completion. If the process stalls or exceeds this, the wrapper assumes completion and resumes normal operations. *(sec)*

Example: `180.0` | +| `bg_drop_blue_connections` | Boolean | No | `true` | Whether to invalidate connections that were opened to the old blue environment before a switchover. Once the switchover is confirmed (it reaches the `POST` or `COMPLETED` phase), each such connection is closed the next time it is used. With the failover plugin enabled, that use reconnects through Blue/Green routing and raises `FailoverSuccessError` (or `TransactionStateUnknownError` inside a transaction); without it, the driver raises its closed-connection error. Either way the application gets an explicit error instead of a stale read from the old blue environment. Connections are invalidated only if the plugin saw the switchover while it was in progress, and none are invalidated if the switchover rolls back.

Example: `false` | ## Configuring monitoring connections diff --git a/site/src/generated/scenarios-ruby.json b/site/src/generated/scenarios-ruby.json index fda81b5..2c59f53 100644 --- a/site/src/generated/scenarios-ruby.json +++ b/site/src/generated/scenarios-ruby.json @@ -1165,6 +1165,7 @@ ], "notes": [ "The plugin holds traffic during the switchover instead of letting it fail, then resumes against the promoted deployment.", + "After the switchover, connections that were opened to the old blue environment are closed the next time they are used. With the failover plugin (on by default), that use raises `FailoverSuccessError` (or `TransactionStateUnknownError` inside a transaction) on a connection that is already reconnected to the new environment, so handle it as you would a failover. Set `bg_drop_blue_connections: false` to keep using those connections instead.", "If you connect through an RDS Proxy, AWS requires the blue cluster to be registered with the proxy before the Blue/Green deployment is created \u2014 you cannot add the proxy afterward." ], "links": [ From af96dfb19b9d8cd738011f42210180f41b2d1d75 Mon Sep 17 00:00:00 2001 From: aaron-congo Date: Wed, 4 Nov 2026 17:02:07 -0700 Subject: [PATCH 2/3] docs-v1.1.0 (ruby): address review comments - Correct how error 2055 surfaced under aws_mysql2 before 1.1.0 (StatementInvalid, not ConnectionFailed). - Say the failover plugin must be listed alongside bg rather than calling it on by default, and note the cost of opting out. - Move blue-connection invalidation into the After the switchover phase, add it to the phase diagram, and cover the ActiveRecord retry and switchover-timeout cases in bg_drop_blue_connections. - Add aws_trilogy to the ActiveRecord adapter lists on the failover page, and qualify the idle-connection and MySQL version wording. - Note that ActiveRecord's query retries skip FailoverSuccessError. - Update the remaining dev-guide references to register_access. --- content/dev-guide.yaml | 6 +++--- content/failover.yaml | 18 +++++++++--------- content/plugins.yaml | 5 ++--- content/scenarios.yaml | 7 +++++-- content/templates/plugin-blue-green.md.j2 | 1 + .../development-guide/service-container.md | 6 +++--- site/docs-ruby/enhanced-failover.md | 16 ++++++++-------- site/docs-ruby/using-plugins/blue-green.md | 6 +++--- site/src/generated/scenarios-ruby.json | 4 ++-- 9 files changed, 36 insertions(+), 33 deletions(-) diff --git a/content/dev-guide.yaml b/content/dev-guide.yaml index a418db7..45ee451 100644 --- a/content/dev-guide.yaml +++ b/content/dev-guide.yaml @@ -297,8 +297,8 @@ wrappers: background cleanup thread. Shared across the wrapper. offers: | - `register(name, ttl:)` — create a named cache partition. - - `set(name, key, value)` / `get(name, key)` — store and read items. - - `get_if_registered(name, key)` — read a partition that may not exist (e.g. a cache owned by an optional plugin). + - `set(name, key, value)` / `get(name, key, register_access: false)` — store and read items. + - `get_if_registered(name, key, register_access: false)` — read a partition that may not exist (e.g. a cache owned by an optional plugin). - `exists?(name, key)` / `remove(name, key)` / `clear(name)` / `clear_all`. whenToUse: | Use it to cache data reused across the wrapper — for example the @@ -335,7 +335,7 @@ wrappers: - `release_resources` — stop the background publishing thread. whenToUse: | Use it to decouple event producers and consumers. For example the Storage - Service publishes a `DataAccessEvent` on cache reads, and the Monitor Service + Service publishes a `DataAccessEvent` on cache reads made with `register_access: true`, and the Monitor Service subscribes to it to extend the matching monitor's expiration. - name: "Plugin Manager" short: "Plugin Manager" diff --git a/content/failover.yaml b/content/failover.yaml index c6d6403..43206bf 100644 --- a/content/failover.yaml +++ b/content/failover.yaml @@ -240,7 +240,7 @@ wrapperOnly: - | ### ActiveRecord integration - Through ActiveRecord (the `aws_postgresql` / `aws_mysql2` adapters), the adapter's + Through ActiveRecord (the `aws_postgresql` / `aws_mysql2` / `aws_trilogy` adapters), the adapter's `translate_exception` decides what your code rescues, and only one failover error is translated: @@ -383,7 +383,7 @@ enhanced: thirdPartyNote: ruby: | :::note Using the wrapper through ActiveRecord - When you use the wrapper through ActiveRecord (`aws_postgresql` or `aws_mysql2`), + When you use the wrapper through ActiveRecord (`aws_postgresql`, `aws_mysql2`, or `aws_trilogy`), reconnection is partially handled for you. On a successful failover the adapter re-runs `configure_connection` and reuses the pooled connection in place rather than discarding it, so you should not call `disconnect!` or discard the connection object @@ -402,9 +402,9 @@ enhanced: - A query that runs longer than the client's `read_timeout`. The driver closes the socket before it raises the timeout, so the connection cannot be reused. - - The first query on a connection that sat idle longer than the server's - `wait_timeout`. MySQL 8.0.24 and later closes such a connection and reports error - 4031. + - A query on a connection that sat idle longer than the server's `wait_timeout`. + The server closes such a connection; MySQL 8.0.24 and later reports error 4031, + and earlier versions report a lost connection (2006 or 2013). - A connection lost during a query, or a server that has gone away (with `mysql2`, errors 2006, 2013, and 2055). @@ -425,15 +425,15 @@ enhanced: :::note Changed in 1.1.0 Before 1.1.0, `mysql2` did not fail over on a `read_timeout` or on errors 4031 and 2055. A `read_timeout` raised `Mysql2::Error::TimeoutError` (`ActiveRecord::AdapterTimeout` - under `aws_mysql2`), and errors 4031 and 2055 were raised as is - (`ActiveRecord::ConnectionFailed` under `aws_mysql2`, which ActiveRecord answered by + under `aws_mysql2`), and errors 4031 and 2055 were raised as is. Under `aws_mysql2`, + error 4031 became `ActiveRecord::ConnectionFailed`, which ActiveRecord answered by reconnecting to the original endpoint and retrying the queries it considers - retryable). + retryable, and error 2055 became `ActiveRecord::StatementInvalid`. ::: - | ## ActiveRecord integration - When using the wrapper through ActiveRecord (`aws_postgresql` or `aws_mysql2`), the + When using the wrapper through ActiveRecord (`aws_postgresql`, `aws_mysql2`, or `aws_trilogy`), the adapter's `translate_exception` decides what your code actually rescues, and the outcome differs by error: diff --git a/content/plugins.yaml b/content/plugins.yaml index 3a55408..39b6fcc 100644 --- a/content/plugins.yaml +++ b/content/plugins.yaml @@ -2183,9 +2183,8 @@ plugins: - **Before the switchover**, it inventories the blue and green endpoints and their IP addresses. - **During the active switchover**, it temporarily suspends calls to blue nodes and substitutes hostnames with the corresponding IP addresses to avoid stale DNS. - - **After the switchover**, it monitors DNS until blue endpoints are reconfigured, then stops substituting. + - **After the switchover**, it monitors DNS until blue endpoints are reconfigured, then stops substituting. From this phase on, it also invalidates connections that were opened to the old blue environment before the switchover, so their next use raises an error instead of reading from retired blue nodes. See `bg_drop_blue_connections` below. - **Once switchover completes**, it rejects new connections to green nodes. - - **Once the switchover is confirmed**, it invalidates connections that were opened to the old blue environment before the switchover, so their next use raises an error instead of reading from retired blue nodes. See `bg_drop_blue_connections` below. - **If the switchover fails or rolls back**, it detects that and restores normal handling. code: ruby: bg @@ -2249,7 +2248,7 @@ plugins: ruby: { name: bg_switchover_timeout_sec, type: float, required: "No", default: "180.0", unit: s, example: "180.0" } - concept: dropBlueConnections type: boolean - description: "Whether to invalidate connections that were opened to the old blue environment before a switchover. Once the switchover is confirmed (it reaches the `POST` or `COMPLETED` phase), each such connection is closed the next time it is used. With the failover plugin enabled, that use reconnects through Blue/Green routing and raises `FailoverSuccessError` (or `TransactionStateUnknownError` inside a transaction); without it, the driver raises its closed-connection error. Either way the application gets an explicit error instead of a stale read from the old blue environment. Connections are invalidated only if the plugin saw the switchover while it was in progress, and none are invalidated if the switchover rolls back." + description: "Whether to invalidate connections that were opened to the old blue environment before a switchover. Once the switchover is confirmed (it reaches the Post or Completed phase), each such connection is closed the next time it is used. With the failover plugin enabled, that use reconnects through Blue/Green routing and raises `FailoverSuccessError` (or `TransactionStateUnknownError` inside a transaction). Without it, the driver raises its closed-connection error; under ActiveRecord, a query it considers retryable may instead be reconnected and retried for you. In neither case is a stale read served from the old blue environment. Connections are invalidated only if the plugin saw the switchover while it was in progress, and none are invalidated if the switchover rolls back, or if `bg_switchover_timeout_sec` elapses before the switchover reaches the Post phase." spellings: ruby: { name: bg_drop_blue_connections, required: "No", default: "true", example: "false" } monitoringPrefix: diff --git a/content/scenarios.yaml b/content/scenarios.yaml index 1c4faf7..f89c8cd 100644 --- a/content/scenarios.yaml +++ b/content/scenarios.yaml @@ -492,7 +492,10 @@ addons: short: query retries requires: { integration: [active_record] } blocked: Active Record supplies this. Talking to the gem directly, retrying is your code's decision. - hint: Active Record retries safely retryable queries once by default. + hint: > + Active Record retries safely retryable queries once by default. It does not + retry `FailoverSuccessError` or `TransactionStateUnknownError`, which the + failover plugin raises after a successful failover. emit: pool: { connection_retries: 3, retry_deadline: 5 } links: [ar_retries] @@ -578,7 +581,7 @@ addons: - "A Blue/Green Deployment exists and the wrapper can read its status before the switchover starts." notes: - "The plugin holds traffic during the switchover instead of letting it fail, then resumes against the promoted deployment." - - "After the switchover, connections that were opened to the old blue environment are closed the next time they are used. With the failover plugin (on by default), that use raises `FailoverSuccessError` (or `TransactionStateUnknownError` inside a transaction) on a connection that is already reconnected to the new environment, so handle it as you would a failover. Set `bg_drop_blue_connections: false` to keep using those connections instead." + - "After the switchover, connections that were opened to the old blue environment are closed the next time they are used. If the failover plugin is enabled (list `failover` in `wrapper_plugins` alongside `bg`), that use raises `FailoverSuccessError` (or `TransactionStateUnknownError` inside a transaction) on a connection that is already reconnected to the new environment, so handle it as you would a failover. Set `bg_drop_blue_connections: false` to keep using those connections instead, at the risk of reading from the retired blue environment." - "If you connect through an RDS Proxy, AWS requires the blue cluster to be registered with the proxy before the Blue/Green deployment is created — you cannot add the proxy afterward." links: [rds_bluegreen] diff --git a/content/templates/plugin-blue-green.md.j2 b/content/templates/plugin-blue-green.md.j2 index 757b1d6..16292c6 100644 --- a/content/templates/plugin-blue-green.md.j2 +++ b/content/templates/plugin-blue-green.md.j2 @@ -30,6 +30,7 @@ stateDiagram-v2 end note note right of Post Monitor DNS; stop substitution; + invalidate pre-switchover blue connections; reject new connections to green nodes end note ``` diff --git a/site/docs-ruby/development-guide/service-container.md b/site/docs-ruby/development-guide/service-container.md index 11e7f86..4ca99ff 100644 --- a/site/docs-ruby/development-guide/service-container.md +++ b/site/docs-ruby/development-guide/service-container.md @@ -148,8 +148,8 @@ background cleanup thread. Shared across the wrapper. **What it offers** - `register(name, ttl:)` — create a named cache partition. -- `set(name, key, value)` / `get(name, key)` — store and read items. -- `get_if_registered(name, key)` — read a partition that may not exist (e.g. a cache owned by an optional plugin). +- `set(name, key, value)` / `get(name, key, register_access: false)` — store and read items. +- `get_if_registered(name, key, register_access: false)` — read a partition that may not exist (e.g. a cache owned by an optional plugin). - `exists?(name, key)` / `remove(name, key)` / `clear(name)` / `clear_all`. **When to use it** @@ -196,7 +196,7 @@ events synchronously and batches the rest, deduplicating via `Set` semantics. **When to use it** Use it to decouple event producers and consumers. For example the Storage -Service publishes a `DataAccessEvent` on cache reads, and the Monitor Service +Service publishes a `DataAccessEvent` on cache reads made with `register_access: true`, and the Monitor Service subscribes to it to extend the matching monitor's expiration. ### Plugin Manager diff --git a/site/docs-ruby/enhanced-failover.md b/site/docs-ruby/enhanced-failover.md index e36c96e..d52c778 100644 --- a/site/docs-ruby/enhanced-failover.md +++ b/site/docs-ruby/enhanced-failover.md @@ -224,7 +224,7 @@ first and reuse the connection when failover succeeded. ::: :::note Using the wrapper through ActiveRecord -When you use the wrapper through ActiveRecord (`aws_postgresql` or `aws_mysql2`), +When you use the wrapper through ActiveRecord (`aws_postgresql`, `aws_mysql2`, or `aws_trilogy`), reconnection is partially handled for you. On a successful failover the adapter re-runs `configure_connection` and reuses the pooled connection in place rather than discarding it, so you should not call `disconnect!` or discard the connection object @@ -240,9 +240,9 @@ includes: - A query that runs longer than the client's `read_timeout`. The driver closes the socket before it raises the timeout, so the connection cannot be reused. -- The first query on a connection that sat idle longer than the server's - `wait_timeout`. MySQL 8.0.24 and later closes such a connection and reports error - 4031. +- A query on a connection that sat idle longer than the server's `wait_timeout`. + The server closes such a connection; MySQL 8.0.24 and later reports error 4031, + and earlier versions report a lost connection (2006 or 2013). - A connection lost during a query, or a server that has gone away (with `mysql2`, errors 2006, 2013, and 2055). @@ -263,15 +263,15 @@ healthy, and the driver's error is raised as usual. :::note Changed in 1.1.0 Before 1.1.0, `mysql2` did not fail over on a `read_timeout` or on errors 4031 and 2055. A `read_timeout` raised `Mysql2::Error::TimeoutError` (`ActiveRecord::AdapterTimeout` -under `aws_mysql2`), and errors 4031 and 2055 were raised as is -(`ActiveRecord::ConnectionFailed` under `aws_mysql2`, which ActiveRecord answered by +under `aws_mysql2`), and errors 4031 and 2055 were raised as is. Under `aws_mysql2`, +error 4031 became `ActiveRecord::ConnectionFailed`, which ActiveRecord answered by reconnecting to the original endpoint and retrying the queries it considers -retryable). +retryable, and error 2055 became `ActiveRecord::StatementInvalid`. ::: ## ActiveRecord integration -When using the wrapper through ActiveRecord (`aws_postgresql` or `aws_mysql2`), the +When using the wrapper through ActiveRecord (`aws_postgresql`, `aws_mysql2`, or `aws_trilogy`), the adapter's `translate_exception` decides what your code actually rescues, and the outcome differs by error: diff --git a/site/docs-ruby/using-plugins/blue-green.md b/site/docs-ruby/using-plugins/blue-green.md index d5941cb..e353ab5 100644 --- a/site/docs-ruby/using-plugins/blue-green.md +++ b/site/docs-ruby/using-plugins/blue-green.md @@ -16,9 +16,8 @@ switchover status and adjusting connection handling at each phase: - **Before the switchover**, it inventories the blue and green endpoints and their IP addresses. - **During the active switchover**, it temporarily suspends calls to blue nodes and substitutes hostnames with the corresponding IP addresses to avoid stale DNS. -- **After the switchover**, it monitors DNS until blue endpoints are reconfigured, then stops substituting. +- **After the switchover**, it monitors DNS until blue endpoints are reconfigured, then stops substituting. From this phase on, it also invalidates connections that were opened to the old blue environment before the switchover, so their next use raises an error instead of reading from retired blue nodes. See `bg_drop_blue_connections` below. - **Once switchover completes**, it rejects new connections to green nodes. -- **Once the switchover is confirmed**, it invalidates connections that were opened to the old blue environment before the switchover, so their next use raises an error instead of reading from retired blue nodes. See `bg_drop_blue_connections` below. - **If the switchover fails or rolls back**, it detects that and restores normal handling. @@ -62,6 +61,7 @@ stateDiagram-v2 end note note right of Post Monitor DNS; stop substitution; + invalidate pre-switchover blue connections; reject new connections to green nodes end note ``` @@ -93,7 +93,7 @@ Verify plugin compatibility within your Ruby configuration using the [compatibil | `bg_increased_sec` | Float | No | `1.0` | Increased interval for checking Blue/Green Deployment status. Configure within 0.5–2 sec. *(sec)*

Example: `1.0` | | `bg_high_sec` | Float | No | `0.1` | High-frequency interval for checking Blue/Green Deployment status. Configure within 0.05–0.5 sec. *(sec)*

Example: `0.1` | | `bg_switchover_timeout_sec` | Float | No | `180.0` | Maximum duration allowed for switchover completion. If the process stalls or exceeds this, the wrapper assumes completion and resumes normal operations. *(sec)*

Example: `180.0` | -| `bg_drop_blue_connections` | Boolean | No | `true` | Whether to invalidate connections that were opened to the old blue environment before a switchover. Once the switchover is confirmed (it reaches the `POST` or `COMPLETED` phase), each such connection is closed the next time it is used. With the failover plugin enabled, that use reconnects through Blue/Green routing and raises `FailoverSuccessError` (or `TransactionStateUnknownError` inside a transaction); without it, the driver raises its closed-connection error. Either way the application gets an explicit error instead of a stale read from the old blue environment. Connections are invalidated only if the plugin saw the switchover while it was in progress, and none are invalidated if the switchover rolls back.

Example: `false` | +| `bg_drop_blue_connections` | Boolean | No | `true` | Whether to invalidate connections that were opened to the old blue environment before a switchover. Once the switchover is confirmed (it reaches the Post or Completed phase), each such connection is closed the next time it is used. With the failover plugin enabled, that use reconnects through Blue/Green routing and raises `FailoverSuccessError` (or `TransactionStateUnknownError` inside a transaction). Without it, the driver raises its closed-connection error; under ActiveRecord, a query it considers retryable may instead be reconnected and retried for you. In neither case is a stale read served from the old blue environment. Connections are invalidated only if the plugin saw the switchover while it was in progress, and none are invalidated if the switchover rolls back, or if `bg_switchover_timeout_sec` elapses before the switchover reaches the Post phase.

Example: `false` | ## Configuring monitoring connections diff --git a/site/src/generated/scenarios-ruby.json b/site/src/generated/scenarios-ruby.json index 2c59f53..40e7358 100644 --- a/site/src/generated/scenarios-ruby.json +++ b/site/src/generated/scenarios-ruby.json @@ -1003,7 +1003,7 @@ ] }, "blocked": "Active Record supplies this. Talking to the gem directly, retrying is your code's decision.", - "hint": "Active Record retries safely retryable queries once by default.", + "hint": "Active Record retries safely retryable queries once by default. It does not retry `FailoverSuccessError` or `TransactionStateUnknownError`, which the failover plugin raises after a successful failover.\n", "emit": { "pool": { "connection_retries": 3, @@ -1165,7 +1165,7 @@ ], "notes": [ "The plugin holds traffic during the switchover instead of letting it fail, then resumes against the promoted deployment.", - "After the switchover, connections that were opened to the old blue environment are closed the next time they are used. With the failover plugin (on by default), that use raises `FailoverSuccessError` (or `TransactionStateUnknownError` inside a transaction) on a connection that is already reconnected to the new environment, so handle it as you would a failover. Set `bg_drop_blue_connections: false` to keep using those connections instead.", + "After the switchover, connections that were opened to the old blue environment are closed the next time they are used. If the failover plugin is enabled (list `failover` in `wrapper_plugins` alongside `bg`), that use raises `FailoverSuccessError` (or `TransactionStateUnknownError` inside a transaction) on a connection that is already reconnected to the new environment, so handle it as you would a failover. Set `bg_drop_blue_connections: false` to keep using those connections instead, at the risk of reading from the retired blue environment.", "If you connect through an RDS Proxy, AWS requires the blue cluster to be registered with the proxy before the Blue/Green deployment is created \u2014 you cannot add the proxy afterward." ], "links": [ From 9f5d3dc55988c3aaab1f0b10750130414e0e2dfe Mon Sep 17 00:00:00 2001 From: aaron-congo Date: Thu, 5 Nov 2026 11:37:54 -0700 Subject: [PATCH 3/3] docs-v1.1.0 (ruby): list every failover error a blue connection can raise With the failover plugin, reusing an invalidated blue connection can still fail to reconnect and raise FailoverFailedError, so name all three failover errors and link to them instead of implying the reconnect always succeeds. --- content/plugins.yaml | 2 +- content/scenarios.yaml | 2 +- site/docs-ruby/using-plugins/blue-green.md | 2 +- site/src/generated/scenarios-ruby.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/content/plugins.yaml b/content/plugins.yaml index 4ec803a..89447b0 100644 --- a/content/plugins.yaml +++ b/content/plugins.yaml @@ -2138,7 +2138,7 @@ plugins: ruby: { name: bg_switchover_timeout_sec, type: float, required: "No", default: "180.0", unit: s, example: "180.0" } - concept: dropBlueConnections type: boolean - description: "Whether to invalidate connections that were opened to the old blue environment before a switchover. Once the switchover is confirmed (it reaches the Post or Completed phase), each such connection is closed the next time it is used. With the failover plugin enabled, that use reconnects through Blue/Green routing and raises `FailoverSuccessError` (or `TransactionStateUnknownError` inside a transaction). Without it, the driver raises its closed-connection error; under ActiveRecord, a query it considers retryable may instead be reconnected and retried for you. In neither case is a stale read served from the old blue environment. Connections are invalidated only if the plugin saw the switchover while it was in progress, and none are invalidated if the switchover rolls back, or if `bg_switchover_timeout_sec` elapses before the switchover reaches the Post phase." + description: "Whether to invalidate connections that were opened to the old blue environment before a switchover. Once the switchover is confirmed (it reaches the Post or Completed phase), each such connection is closed the next time it is used. With the failover plugin enabled, that use triggers failover through Blue/Green routing and raises one of the [failover errors](../enhanced-failover#failover-errors): `FailoverSuccessError` or `TransactionStateUnknownError` (inside a transaction) when it reconnects, or `FailoverFailedError` when it cannot, for example during a network disconnect. Without it, the driver raises its closed-connection error; under ActiveRecord, a query it considers retryable may instead be reconnected and retried for you. In neither case is a stale read served from the old blue environment. Connections are invalidated only if the plugin saw the switchover while it was in progress, and none are invalidated if the switchover rolls back, or if `bg_switchover_timeout_sec` elapses before the switchover reaches the Post phase." spellings: ruby: { name: bg_drop_blue_connections, required: "No", default: "true", example: "false" } monitoringPrefix: diff --git a/content/scenarios.yaml b/content/scenarios.yaml index cec7f4a..aa2579d 100644 --- a/content/scenarios.yaml +++ b/content/scenarios.yaml @@ -581,7 +581,7 @@ addons: - "A Blue/Green Deployment exists and the wrapper can read its status before the switchover starts." notes: - "The plugin holds traffic during the switchover instead of letting it fail, then resumes against the promoted deployment." - - "After the switchover, connections that were opened to the old blue environment are closed the next time they are used. If the failover plugin is enabled (list `failover` in `wrapper_plugins` alongside `bg`), that use raises `FailoverSuccessError` (or `TransactionStateUnknownError` inside a transaction) on a connection that is already reconnected to the new environment, so handle it as you would a failover. Set `bg_drop_blue_connections: false` to keep using those connections instead, at the risk of reading from the retired blue environment." + - "After the switchover, connections that were opened to the old blue environment are closed the next time they are used. If the failover plugin is enabled (list `failover` in `wrapper_plugins` alongside `bg`), that use triggers failover and raises one of the failover errors: `FailoverSuccessError` (or `TransactionStateUnknownError` inside a transaction) when the connection reconnects to the new environment, or `FailoverFailedError` when it cannot. Handle it as you would any other failover. Set `bg_drop_blue_connections: false` to keep using those connections instead, at the risk of reading from the retired blue environment." - "If you connect through an RDS Proxy, AWS requires the blue cluster to be registered with the proxy before the Blue/Green deployment is created — you cannot add the proxy afterward." links: [rds_bluegreen] diff --git a/site/docs-ruby/using-plugins/blue-green.md b/site/docs-ruby/using-plugins/blue-green.md index e353ab5..36e82ef 100644 --- a/site/docs-ruby/using-plugins/blue-green.md +++ b/site/docs-ruby/using-plugins/blue-green.md @@ -93,7 +93,7 @@ Verify plugin compatibility within your Ruby configuration using the [compatibil | `bg_increased_sec` | Float | No | `1.0` | Increased interval for checking Blue/Green Deployment status. Configure within 0.5–2 sec. *(sec)*

Example: `1.0` | | `bg_high_sec` | Float | No | `0.1` | High-frequency interval for checking Blue/Green Deployment status. Configure within 0.05–0.5 sec. *(sec)*

Example: `0.1` | | `bg_switchover_timeout_sec` | Float | No | `180.0` | Maximum duration allowed for switchover completion. If the process stalls or exceeds this, the wrapper assumes completion and resumes normal operations. *(sec)*

Example: `180.0` | -| `bg_drop_blue_connections` | Boolean | No | `true` | Whether to invalidate connections that were opened to the old blue environment before a switchover. Once the switchover is confirmed (it reaches the Post or Completed phase), each such connection is closed the next time it is used. With the failover plugin enabled, that use reconnects through Blue/Green routing and raises `FailoverSuccessError` (or `TransactionStateUnknownError` inside a transaction). Without it, the driver raises its closed-connection error; under ActiveRecord, a query it considers retryable may instead be reconnected and retried for you. In neither case is a stale read served from the old blue environment. Connections are invalidated only if the plugin saw the switchover while it was in progress, and none are invalidated if the switchover rolls back, or if `bg_switchover_timeout_sec` elapses before the switchover reaches the Post phase.

Example: `false` | +| `bg_drop_blue_connections` | Boolean | No | `true` | Whether to invalidate connections that were opened to the old blue environment before a switchover. Once the switchover is confirmed (it reaches the Post or Completed phase), each such connection is closed the next time it is used. With the failover plugin enabled, that use triggers failover through Blue/Green routing and raises one of the [failover errors](../enhanced-failover#failover-errors): `FailoverSuccessError` or `TransactionStateUnknownError` (inside a transaction) when it reconnects, or `FailoverFailedError` when it cannot, for example during a network disconnect. Without it, the driver raises its closed-connection error; under ActiveRecord, a query it considers retryable may instead be reconnected and retried for you. In neither case is a stale read served from the old blue environment. Connections are invalidated only if the plugin saw the switchover while it was in progress, and none are invalidated if the switchover rolls back, or if `bg_switchover_timeout_sec` elapses before the switchover reaches the Post phase.

Example: `false` | ## Configuring monitoring connections diff --git a/site/src/generated/scenarios-ruby.json b/site/src/generated/scenarios-ruby.json index 8722f6e..5b72d1e 100644 --- a/site/src/generated/scenarios-ruby.json +++ b/site/src/generated/scenarios-ruby.json @@ -1165,7 +1165,7 @@ ], "notes": [ "The plugin holds traffic during the switchover instead of letting it fail, then resumes against the promoted deployment.", - "After the switchover, connections that were opened to the old blue environment are closed the next time they are used. If the failover plugin is enabled (list `failover` in `wrapper_plugins` alongside `bg`), that use raises `FailoverSuccessError` (or `TransactionStateUnknownError` inside a transaction) on a connection that is already reconnected to the new environment, so handle it as you would a failover. Set `bg_drop_blue_connections: false` to keep using those connections instead, at the risk of reading from the retired blue environment.", + "After the switchover, connections that were opened to the old blue environment are closed the next time they are used. If the failover plugin is enabled (list `failover` in `wrapper_plugins` alongside `bg`), that use triggers failover and raises one of the failover errors: `FailoverSuccessError` (or `TransactionStateUnknownError` inside a transaction) when the connection reconnects to the new environment, or `FailoverFailedError` when it cannot. Handle it as you would any other failover. Set `bg_drop_blue_connections: false` to keep using those connections instead, at the risk of reading from the retired blue environment.", "If you connect through an RDS Proxy, AWS requires the blue cluster to be registered with the proxy before the Blue/Green deployment is created \u2014 you cannot add the proxy afterward." ], "links": [