Skip to content

fix: fail fast on failover and warn when cluster_instance_host_pattern is missing for an IP or custom domain - #235

Merged
aaron-congo merged 8 commits into
mainfrom
fix/failover-non-rds-host-pattern
Dec 1, 2026
Merged

aaron-congo merged 8 commits into
mainfrom
fix/failover-non-rds-host-pattern

Conversation

@aaron-congo

@aaron-congo aaron-congo commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

When the connection host isn't a recognized RDS endpoint and cluster_instance_host_pattern isn't set, warn at connect and make failover raise FailoverFailedError immediately, instead of retrying instance hosts that can't be resolved until failover_timeout_sec.

Description

When the connection host is an IP address or a custom domain/CNAME and cluster_instance_host_pattern isn't set, RdsHostListProvider falls back to a bare ? instance template. With the previous code, this template passes validation, and nothing is logged. The topology monitor then builds instance hosts as bare instance identifiers, which usually don't resolve. On a failover it retries them until failover_timeout_sec (300 s by default), and then raises a FailoverFailedError that doesn't mention the missing setting.

Detection

  • RdsHostListProvider#instance_host_pattern_missing? is true when the template is a bare ? and cluster_instance_host_pattern wasn't set.
  • Only cluster dialects (Aurora, RDS Multi-AZ DB cluster) use RdsHostListProvider, so single instances and community databases aren't affected. GlobalAuroraHostListProvider always returns false, because it requires global_cluster_instance_host_patterns.
  • An explicitly set cluster_instance_host_pattern: '?' doesn't count as missing. That's the opt-out for environments where bare instance identifiers resolve, for example through a DNS search domain.

Warning at connect

  • After the initial connection has settled the dialect, FailoverPlugin logs one WARN per host if the pattern is missing. This happens whether failover is listed explicitly in wrapper_plugins or comes from the default list, and the connection still opens.
  • The warning names the host, says failover will fail, and gives the fixes: set cluster_instance_host_pattern (or ? if bare identifiers resolve), or remove failover from wrapper_plugins.
  • A future major version will raise at connect for this configuration instead.

Failover

  • Writer and reader failover, and gdb_failover, check the same condition first. They raise FailoverFailedError ("Failover is not possible. ..." followed by the warning's explanation) without refreshing the topology or connecting.
  • That covers failovers started from execute (network errors, closed connections) and from connect with enable_connect_failover. The attempt counts as a failed failover in telemetry. An explicitly closed connection still re-raises the original error.

gdb_failover

  • On a database identified as a regional cluster (for example wrapper_dialect: aurora-pg, or a single-region Global Database with wrapper_dialect unset), the message explains that global_cluster_instance_host_patterns doesn't apply.
  • For a Global Database member, it says to set wrapper_dialect to the global dialect and set global_cluster_instance_host_patterns. For a standalone cluster, it says to use failover with cluster_instance_host_pattern.

Behavior change
In the rare setup where bare instance identifiers resolve, failover used to succeed and now fails immediately unless cluster_instance_host_pattern: '?' is set. This is flagged in the CHANGELOG.

Docs

  • CHANGELOG entry under Unreleased.
  • The Enhanced Failover and GDB Failover pages and the parameter tables are updated in aws-advanced-wrapper-docs (separate PR).

Testing

  • Unit specs cover:
    • each detection condition, including the cases that must not warn or fail: non-cluster dialects, RDS endpoints, a set pattern, an explicit ?, and Global Databases;
    • the warning appearing once per host at the default INFO level, for explicit and default plugin lists, and again after clear_caches;
    • immediate failure through execute and connect, in writer and reader modes and for gdb_failover;
    • normal failover when the pattern is set.
  • bundle exec rspec spec/unit and bundle exec rubocop pass.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

…P or custom domain

When the connection host isn't a recognized RDS endpoint and
cluster_instance_host_pattern isn't set, instance hosts are built as bare
instance identifiers that usually don't resolve, so failover retried until
failover_timeout_sec (300 s by default).

- On Aurora and RDS Multi-AZ DB clusters, connections that list failover
  explicitly in wrapper_plugins now raise at startup, naming the host and
  both fixes. With the default plugin list, a warning is logged once per host.
- The topology monitor records unresolvable instance hosts as a fatal
  configuration error, so writer failover raises FailoverFailedError right
  away. Reader failover and writer connection attempts check for the same
  condition. Temporary DNS failures and other network errors still retry.
- gdb_failover on a database identified as a regional cluster gets its own
  message explaining that global_cluster_instance_host_patterns doesn't apply.
- Driver error handlers gain unknown_host_error? for mysql2, pg and trilogy.
@aaron-congo
aaron-congo requested a review from a team as a code owner November 4, 2026 19:24
@aaron-congo
aaron-congo marked this pull request as draft November 4, 2026 20:02
…ttern is missing

Connections whose host isn't a recognized RDS endpoint and that don't set
cluster_instance_host_pattern now log a warning on Aurora and RDS Multi-AZ
DB clusters, whether or not failover is listed explicitly in
wrapper_plugins. Failover still fails fast with FailoverFailedError when an
instance host can't be resolved. A future major version will raise at
connect instead.

- The warning says failover will fail, and keeps the fix that applies
  (remove failover from wrapper_plugins, or set wrapper_plugins without it
  when the default list is in use).
- gdb_failover on a database identified as a regional cluster now warns too,
  and its failover paths get the same fail-fast as failover: the topology
  monitor error becomes FailoverFailedError, and its connection attempts use
  the on_connect_error hook.
- CHANGELOG entry moved to Fixed.
@aaron-congo aaron-congo changed the title fix: fail fast when failover can't resolve instance hosts behind an IP or custom domain fix: fail fast on failover and warn when cluster_instance_host_pattern is missing for an IP or custom domain Nov 4, 2026
@aaron-congo
aaron-congo marked this pull request as ready for review November 4, 2026 22:52
sophia-bq
sophia-bq previously approved these changes Nov 5, 2026
Comment on lines +164 to +168
"The connection host '#{host}' is not a recognized RDS endpoint and " \
"#{PropertyDefinition::CLUSTER_INSTANCE_HOST_PATTERN.name} is not set, so the #{plugin_code} plugin cannot " \
'build DB instance hosts from the cluster topology, and failover will fail with FailoverFailedError. ' \
"Set #{PropertyDefinition::CLUSTER_INSTANCE_HOST_PATTERN.name} to a DNS pattern that resolves to the " \
"cluster's instances (for example, '?.XXX.us-east-1.rds.amazonaws.com'), or #{remedy}."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious to what degree we can reuse UnresolvableInstanceHostError in these cases instead of maintaining multiple locations of a similar text block

Comment on lines +437 to +445
"The connection host '#{host}' is not a recognized RDS endpoint, #{pattern_name} is not set, and the " \
'database was identified as a regional cluster rather than an Aurora Global Database, so ' \
"#{PropertyDefinition::GLOBAL_CLUSTER_INSTANCE_HOST_PATTERNS.name} does not apply and the #{PLUGIN_CODE} " \
'plugin cannot build DB instance hosts from the cluster topology, and failover will fail with ' \
'FailoverFailedError. If the cluster is a member of a Global ' \
"Database, set #{PropertyDefinition::DIALECT.name} to '#{global_dialect_code}' (without it, a Global " \
'Database is only detected when it spans more than one region). For a standalone cluster, use the ' \
"failover plugin instead, and set #{pattern_name} to a DNS pattern that resolves to the cluster's " \
"instances (for example, '?.XXX.us-east-1.rds.amazonaws.com')."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here on whether we can reuse the message in UnresolvableInstanceHostError


if unresolvable_due_to_misconfiguration?(e)
# Retrying can't help, since the host is a bare instance identifier that will never resolve.
record_fatal_error(Errors::UnresolvableInstanceHostError.new(host_info.host, initial_host_info&.host))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So just in terms of new behaviours introduced this does fail slightly faster than in 1.0.1 but only in cases where it would have definitely timed out?

@steve-gore-snapdocs

Copy link
Copy Markdown

We ran into this in our initial implementation. I think this would be a helpful addition.

@sophia-bq

Copy link
Copy Markdown
Contributor

We ran into this in our initial implementation. I think this would be a helpful addition.

Thank you @steve-gore-snapdocs for letting us know. We'll be sure to include this fix in the next release!

…host-pattern

# Conflicts:
#	lib/aws_advanced_ruby_driver_wrapper/errors/error_handler.rb
#	lib/aws_advanced_ruby_driver_wrapper/services/dialect_service.rb
…missing

Replace the DNS-based fail-fast with a configuration check. When the
connection host isn't a recognized RDS endpoint and
cluster_instance_host_pattern isn't set, failover (writer, reader and
gdb_failover) now raises FailoverFailedError as soon as it starts, with the
same explanation as the warning logged at connect, instead of waiting for
instance hosts to fail to resolve. An explicitly set '?' pattern opts out of
both, for environments where bare instance identifiers resolve.

- Remove the topology monitor's fatal error, the RetryUtil on_connect_error
  hook, the reader-failover check, and unknown_host_error? from the error
  handlers, along with UnresolvableInstanceHostError.
- Build the warning and the failover error from the same message methods on
  FailoverPlugin; gdb_failover overrides only its problem and fix wording,
  and its fix now also says to set global_cluster_instance_host_patterns.
- Warnings mention the '?' opt-out and read as separate sentences.
- Add specs that go through execute and connect, and flag the behavior
  change in the CHANGELOG.
…ing cluster_instance_host_pattern

Update the configuration and troubleshooting assistants for the new
behavior, tagged [Unreleased] with before/after wording: a warning at
connect, an immediate FailoverFailedError on failover, the '?' opt-out,
and the gdb_failover regional-cluster message.
| `in_home_failover_mode` | String | depends on URL | Mode while the primary **is** the home region (§9.2). Writer or global writer endpoint → `strict_writer`; other endpoints → `home_reader_or_writer`. |
| `out_of_home_failover_mode` | String | depends on URL | Mode while the primary **is not** the home region. Same values and derivation as above. |
| `global_cluster_instance_host_patterns` | String | none | Comma-separated instance host patterns for every region, e.g. `?.xyz1.us-east-1.rds.amazonaws.com,?.xyz2.us-west-1.rds.amazonaws.com`. Prefix custom-domain patterns with `[region]`. Required for Global Databases. |
| `global_cluster_instance_host_patterns` | String | none | Comma-separated instance host patterns for every region, e.g. `?.xyz1.us-east-1.rds.amazonaws.com,?.xyz2.us-west-1.rds.amazonaws.com`. Prefix custom-domain patterns with `[region]`. Required for Global Databases. Only read for `global-aurora-*` dialects. [Unreleased] `gdb_failover` on a database identified as a regional cluster (e.g. `wrapper_dialect: aurora-pg`, or a single-region Global Database with `wrapper_dialect` unset) behind an IP / own domain without `cluster_instance_host_pattern` logs a `WARN` that this setting doesn't apply, and failover raises `FailoverFailedError` immediately. |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| `global_cluster_instance_host_patterns` | String | none | Comma-separated instance host patterns for every region, e.g. `?.xyz1.us-east-1.rds.amazonaws.com,?.xyz2.us-west-1.rds.amazonaws.com`. Prefix custom-domain patterns with `[region]`. Required for Global Databases. Only read for `global-aurora-*` dialects. [Unreleased] `gdb_failover` on a database identified as a regional cluster (e.g. `wrapper_dialect: aurora-pg`, or a single-region Global Database with `wrapper_dialect` unset) behind an IP / own domain without `cluster_instance_host_pattern` logs a `WARN` that this setting doesn't apply, and failover raises `FailoverFailedError` immediately. |
| `global_cluster_instance_host_patterns` | String | none | Comma-separated instance host patterns for every region, e.g. `?.xyz1.us-east-1.rds.amazonaws.com,?.xyz2.us-west-1.rds.amazonaws.com`. Prefix custom-domain patterns with `[region]`. Required for Global Databases. Only read for `global-aurora-*` dialects. [Unreleased] `gdb_failover` on a database identified as a regional cluster (e.g. `wrapper_dialect: aurora-pg`, or a single-region Global Database with `wrapper_dialect` unset) behind an IP / own domain without `global_cluster_instance_host_pattern` logs a `WARN` that this setting doesn't apply, and failover raises `FailoverFailedError` immediately. |

It should be clear what properties need to be set in the gdb and not gdb case - does a user need to set global_cluster_instance_host_patterns and cluster_instance_host_patterns for a gdb? Similar wording exists in the troubleshooting skill

sophia-bq
sophia-bq previously approved these changes Nov 30, 2026
A Global Database only needs global_cluster_instance_host_patterns; on a
regional dialect that setting is ignored and cluster_instance_host_pattern
applies instead.
@aaron-congo
aaron-congo merged commit 7e88f74 into main Dec 1, 2026
14 checks passed
@aaron-congo
aaron-congo deleted the fix/failover-non-rds-host-pattern branch December 1, 2026 20:04
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.

3 participants