mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06: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
|
@result = nil
|
||||||
|
|
||||||
@queue ||= Queue.new
|
@queue ||= Queue.new
|
||||||
@queue << ""
|
|
||||||
ensure_lookup_thread
|
ensure_lookup_thread
|
||||||
|
|
||||||
@lookup = addr
|
@lookup = addr
|
||||||
@parent = Thread.current
|
@parent = Thread.current
|
||||||
|
|
||||||
|
# Wakeup the worker thread
|
||||||
|
@queue << ""
|
||||||
|
|
||||||
# This sleep will be interrupted by the lookup thread
|
# This sleep will be interrupted by the lookup thread
|
||||||
# if completed within timeout
|
# if completed within timeout
|
||||||
sleep timeout
|
sleep timeout
|
||||||
|
@ -18,16 +18,12 @@ describe FinalDestination::Resolver do
|
|||||||
|
|
||||||
expect {
|
expect {
|
||||||
result = FinalDestination::Resolver.lookup("sleep.example.com", timeout: 0.001)
|
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)
|
}.to raise_error(Timeout::Error)
|
||||||
|
|
||||||
start_thread_count = alive_thread_count
|
start_thread_count = alive_thread_count
|
||||||
|
|
||||||
expect {
|
expect {
|
||||||
result = FinalDestination::Resolver.lookup("sleep.example.com", timeout: 0.001)
|
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)
|
}.to raise_error(Timeout::Error)
|
||||||
|
|
||||||
expect(alive_thread_count).to eq(start_thread_count)
|
expect(alive_thread_count).to eq(start_thread_count)
|
||||||
|
Loading…
Reference in New Issue
Block a user