Skip to content

Commit

Permalink
Ensure captures the entire Thread.new block
Browse files Browse the repository at this point in the history
  • Loading branch information
grodowski committed Dec 10, 2024
1 parent bde3ee6 commit 5659aa0
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions test/helpers/data_writer_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,27 +134,25 @@ def random_real_id(connection, table)
def start_synchronized_datawriter_threads
@number_of_writers.times do |i|
@threads << Thread.new do
@logger.info("data writer thread in wait mode #{i}")
connection = Mysql2::Client.new(@db_config)
@logger.info("data writer thread in wait mode #{i}")
on_write = @start_cmd.pop
@logger.info("starting data writer thread #{i}")

n = 0
begin
until @stop_requested do
write_data(connection, &on_write)
@started_callback_cmd << n unless @started
n += 1
# Kind of makes the following race condition a bit better...
# https://github.com/Shopify/ghostferry/issues/280
sleep(0.03)
end
ensure
@started_callback_cmd << n unless @started # if #stop_and_join is called before first write
connection.close
until @stop_requested do
write_data(connection, &on_write)
@started_callback_cmd << n unless @started
n += 1
# Kind of makes the following race condition a bit better...
# https://github.com/Shopify/ghostferry/issues/280
sleep(0.03)
end

@logger.info("stopped data writer thread #{i} with a total of #{n} data writes")
ensure
@started_callback_cmd << n unless @started # if #stop_and_join is called before first write
connection&.close
end
end
end
Expand Down

0 comments on commit 5659aa0

Please sign in to comment.