4.1 batched writer discards accepted broadcasts after a failed insert
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 30/100
调研方向
Start by reading BatchedBroadcaster#flush and the reproduction test at test/lib/solid_cable/failed_batch_reproduction_test.rb; compare its behavior with the existing test that covers reporting write errors. The issue leaves the delivery contract and preferred remedy undecided, so clarify that boundary with maintainers before proposing a change. Done means the contract is explicit and the chosen behavior is documented and covered by tests.
由索引模型根据 Issue 内容生成。
描述
Summary
Since 4.1.0's batched writer (#87), broadcast returns after enqueueing, before the database insert. If BatchedBroadcaster#flush encounters an insert error, it reports the exception through Rails.error and discards that batch. A subsequent healthy write succeeds, but the earlier accepted broadcast is never retried, including during graceful shutdown.
This is not a request for exactly-once delivery. The concern is the changed failure boundary: in 4.0.2, the adapter's synchronous write could raise to its caller; in 4.1.0, that caller has already returned and cannot react to this failure.
Reproduction
Verified on upstream main bd0442f84b10c44cbd915d919c74fcd698e02b11 (version 4.1.0), Ruby 4.0.6 / Linux. Save the following as test/lib/solid_cable/failed_batch_reproduction_test.rb and run:
bundle exec bin/test test/lib/solid_cable/failed_batch_reproduction_test.rb
This is a deterministic unit-level fault injection: the first database write raises ActiveRecord::ConnectionFailed; later writes are healthy. The two arrays record attempted and successful writes, not browser delivery.
# frozen_string_literal: true
require "test_helper"
require "config_stubs"
require "timeout"
class SolidCable::FailedBatchReproductionTest < ActiveSupport::TestCase
include ConfigStubs
test "one failed write is reported but its accepted payload is never retried" do
attempted = []
persisted = []
errors = Queue.new
attempts = 0
with_cable_config autotrim: false do
writer = SolidCable::BatchedBroadcaster.new(batch_size: 1, batch_delay: 0)
Rails.error.stub(:report, ->(error, **) { errors << error }) do
write = lambda do |batch|
attempted.concat(batch.map(&:payload))
attempts += 1
raise ActiveRecord::ConnectionFailed, "one injected connection failure" if attempts == 1
persisted.concat(batch.map(&:payload))
end
SolidCable::Message.stub(:broadcast_batch, write) do
writer.broadcast("channel", "first")
assert_instance_of ActiveRecord::ConnectionFailed, Timeout.timeout(5) { errors.pop }
writer.broadcast("channel", "second")
writer.shutdown
end
end
ensure
writer&.shutdown
end
assert_equal [ "first", "second" ], attempted
assert_equal [ "second" ], persisted
end
end
Result: 1 run, 3 assertions, 0 failures/errors. The passing assertions demonstrate the loss, not desired recovery.
We also observed the same discard behavior with a real PostgreSQL CHECK-constraint rejection: the broadcast returned normally, the background insert reported ActiveRecord::CheckViolation, the rejected payload remained absent after removing the constraint and shutting down gracefully, and a later healthy broadcast was stored. That permanent-error probe is not an argument for retrying constraint violations.
Possible direction
Is dropping failed batches the intended delivery contract? The existing reports write errors test covers reporting, so I do not want to assume a guaranteed-delivery contract the project has not made.
A small opt-in synchronous-writing mode could preserve the caller-visible write failure behavior for applications that need it, while retaining default batching. Alternatively, bounded retries of specifically transient write errors could help, but ambiguous commit outcomes, duplicates, permanent errors and shutdown would need an explicit policy.
Happy to contribute a focused PR once the preferred boundary is clear. At minimum, documenting that a successful broadcast return does not establish persistence, and that failed batches are reported and discarded without retry, would make upgrades easier to assess.
- 主要语言
- Ruby
- 星标
- 348
- 派生
- 33
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
rails/solid_cable 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 30/100
rails/solid_cable#100 · 1 条评论 ·
查看 rails/solid_cable 的全部 Issue
相似的 Issue
-
開発用DockerイメージにPlaywrightのシステム依存を追加する可能已有人在做 @momocus 今天认领。 未关闭
难度 1/5 1 小时以内 新手友好度 85/100
sakazuki-org/sakazuki#1453 ·
维护者通常 3 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
jenkins-infra/jenkins.io#9615 · 1 条评论 ·
维护者通常 1 天内回复
-
fix(ocr): compile the Tesseract-free pipeline with Tokio runtime可能已有人在做 @Goldziher 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
Metric tooltips that contradict how the metric is calculated可能已有人在做 @aniadeadu 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
WikiEducationFoundation/WikiEduDashboard#7303 · 1 条评论 ·
维护者通常 1 天内回复
-
WhatsApp Cloud template sync saves a partial template list when one page of the Graph API response fails可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 2 天内回复