From 71b25575018c4c31e7763eb49326f21f964d28a8 Mon Sep 17 00:00:00 2001 From: Kyrylo Silin Date: Sat, 17 Nov 2018 01:13:34 +0800 Subject: [PATCH] route_sender: fix possible race with increment_stats Sometimes we have routes that report 0 count. In theory, this should never happen because if there's a route record, then the count should be at least 1. I suspect this happens due to a possible race between `send` and `increment_stats`. This gets executed: `@routes[route] ||= RouteStat.new` Then the scheduler switches to `send` and sends the routes. This essentially sends the route with zero data. So far I have no better idea and this is kind of a guess rather than a solid proof. --- lib/airbrake-ruby/route_sender.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/airbrake-ruby/route_sender.rb b/lib/airbrake-ruby/route_sender.rb index 155eb5d8..a5e63461 100644 --- a/lib/airbrake-ruby/route_sender.rb +++ b/lib/airbrake-ruby/route_sender.rb @@ -142,9 +142,9 @@ def schedule_flush(promise) routes = @routes @routes = {} @thread = nil - end - send(routes, promise) + send(routes, promise) + end end # Setting a name is needed to test the timer.