From 1f34f653bfb6ccb39a4f4f8085b07e9d94389e6f Mon Sep 17 00:00:00 2001 From: Sam Saffron <sam.saffron@gmail.com> Date: Wed, 11 Mar 2020 17:42:56 +1100 Subject: [PATCH] FIX: last ip address could point at wrong ip Due to unicorn env object recycling request.ip could point at the wrong ip address by the time defer block is called. This usually would happen under load. This also avoids keeping the entire request object as referenced by the closure. --- lib/auth/default_current_user_provider.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/auth/default_current_user_provider.rb b/lib/auth/default_current_user_provider.rb index bdd304ef1b1..5fe22b4adce 100644 --- a/lib/auth/default_current_user_provider.rb +++ b/lib/auth/default_current_user_provider.rb @@ -118,9 +118,11 @@ class Auth::DefaultCurrentUserProvider if current_user && should_update_last_seen? u = current_user + ip = request.ip + Scheduler::Defer.later "Updating Last Seen" do u.update_last_seen! - u.update_ip_address!(request.ip) + u.update_ip_address!(ip) end end