Skip to content

Commit e1e0bb4

Browse files
hinaloeclaude
andcommitted
fix: prevent NoMethodError from LD-Signature failure and tag race
LinkedDataSignature#verify_account! returned `false` from the OpenSSL::PKey::RSAError rescue, which slipped past the `.nil?` check in ProcessCollectionService and left `@account = false`, causing `false.suspended?` later on. Return nil instead to match the rest of the method's contract. Tag.find_or_create_by_names silently returned nil when the post- RecordNotUnique re-lookup failed (e.g. under read-replica lag), which surfaced far away as `nil.valid?` in Activity::Create#process_hashtag. Re-raise the original RecordNotUnique so Sidekiq retries the job instead of propagating a nil tag through the pipeline. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 6a7878b commit e1e0bb4

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

app/lib/activitypub/linked_data_signature.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def verify_account!
2929

3030
creator if creator.keypair.public_key.verify(OpenSSL::Digest.new('SHA256'), Base64.decode64(signature), to_be_verified)
3131
rescue OpenSSL::PKey::RSAError
32-
false
32+
nil
3333
end
3434

3535
def sign!(creator, sign_with: nil)

app/models/tag.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,11 @@ def find_or_create_by_names(name_or_names)
9494
tag = begin
9595
matching_name(normalized_name).first || create!(name: normalized_name)
9696
rescue ActiveRecord::RecordNotUnique
97-
find_normalized(normalized_name)
97+
# A concurrent insert won the race. The row should be visible now,
98+
# but if it isn't (e.g. read-replica lag), re-raise instead of
99+
# silently yielding nil to callers — Sidekiq's retry will pick it
100+
# up once the row is visible.
101+
find_normalized(normalized_name) || raise
98102
end
99103

100104
yield tag if block_given?

0 commit comments

Comments
 (0)