mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 09:42:02 +08:00
DEV: Fix FinalDestination::Resolver race condition (#19558)
We were adding to the resolver's work queue before setting up the `@lookup` and `@parent` information. That could lead to the lookup being performed on the wrong (or `nil`) hostname. This also lead to some flakiness in specs.
This commit is contained in:
parent
2304761223
commit
f1ec8c869a
|
@ -8,12 +8,14 @@ class FinalDestination::Resolver
|
|||
@result = nil
|
||||
|
||||
@queue ||= Queue.new
|
||||
@queue << ""
|
||||
ensure_lookup_thread
|
||||
|
||||
@lookup = addr
|
||||
@parent = Thread.current
|
||||
|
||||
# Wakeup the worker thread
|
||||
@queue << ""
|
||||
|
||||
# This sleep will be interrupted by the lookup thread
|
||||
# if completed within timeout
|
||||
sleep timeout
|
||||
|
|
|
@ -18,16 +18,12 @@ describe FinalDestination::Resolver do
|
|||
|
||||
expect {
|
||||
result = FinalDestination::Resolver.lookup("sleep.example.com", timeout: 0.001)
|
||||
# If the test gets this far, it failed
|
||||
puts "Flaky test debug: Result was #{result.inspect}"
|
||||
}.to raise_error(Timeout::Error)
|
||||
|
||||
start_thread_count = alive_thread_count
|
||||
|
||||
expect {
|
||||
result = FinalDestination::Resolver.lookup("sleep.example.com", timeout: 0.001)
|
||||
# If the test gets this far, it failed
|
||||
puts "Flaky test debug: Result was #{result.inspect}"
|
||||
}.to raise_error(Timeout::Error)
|
||||
|
||||
expect(alive_thread_count).to eq(start_thread_count)
|
||||
|
|
Loading…
Reference in New Issue
Block a user