Skip to content

Fall back when a cable duration setting cannot be parsed - #93

Open
afurm wants to merge 1 commit into
rails:mainfrom
afurm:fix-duration-parse-fallback
Open

afurm wants to merge 1 commit into
rails:mainfrom
afurm:fix-duration-parse-fallback

Conversation

@afurm

@afurm afurm commented Oct 3, 2026

Copy link
Copy Markdown

SolidCable::Configuration#parse_duration is how message_retention, polling_interval, and writer_batch_delay are read from config/cable.yml. The README says a missing message_retention, or one that fails to parse, defaults to 1.day. The parser only split on . and called the last segment as a method, and it rescued nothing.

1.day and 0.1.seconds still work. Anything else raised NoMethodError while the listener was polling or while trim was reading the cutoff:

  • a bare number (1, or YAML 0.1 parsed as a float and then stringified)
  • a phrase such as "1 day"
  • any other value that is not <number>.<unit>

config_for also hands these settings through as numbers. An unquoted YAML number is a Numeric, and <%= 1.day %> becomes that duration's to_s ("86400"), which YAML loads as an integer number of seconds. SolidCable.configure can pass an ActiveSupport::Duration directly. Those are now accepted: a duration is returned as-is, and a number is seconds. A value that still cannot be parsed returns the default already configured for that setting (1.day, 0.1.seconds, or 0.001.seconds).

message_retention, polling_interval, and writer_batch_delay only
accepted strings like 1.day. A bare number, "1 day", or any other
value raised NoMethodError. Parsing now returns that setting's
default, matching the documented message_retention behavior.

Numeric values are seconds, which is how YAML and ERB durations
arrive through config_for. An ActiveSupport::Duration is kept as-is.
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