diff --git a/lib/sessions.rb b/lib/sessions.rb index 925b2eef2..7d299ee7e 100644 --- a/lib/sessions.rb +++ b/lib/sessions.rb @@ -140,7 +140,7 @@ returns destroy session - Sessions.destory?(client_id) + Sessions.destory(client_id) returns @@ -169,7 +169,7 @@ returns list_of_closed_sessions = [] clients = Sessions.list clients.each { |client_id, client| - if ( client[:meta][:last_ping].to_i + ( 60 * idle_time_in_min ) ) < Time.now.to_i + if !client[:meta] || !client[:meta][:last_ping] || ( client[:meta][:last_ping].to_i + ( 60 * idle_time_in_min ) ) < Time.now.to_i list_of_closed_sessions.push client_id Sessions.destory( client_id ) end @@ -221,9 +221,14 @@ returns =end def self.get( client_id ) - session_file = @path + '/' + client_id.to_s + '/session' + session_dir = @path + '/' + client_id.to_s + session_file = session_dir + '/session' data = nil - return if !File.exist? session_file + if !File.exist? session_file + self.destory(client_id) + puts "ERROR: missing session file for '#{client_id.to_s}', remove session." + return + end begin File.open( session_file, 'rb' ) { |file| file.flock( File::LOCK_EX ) @@ -232,9 +237,9 @@ returns data = Marshal.load( all ) } rescue Exception => e - File.delete(session_file) - puts "Error reading '#{session_file}':" puts e.inspect + self.destory(client_id) + puts "ERROR: reading session file '#{session_file}', remove session." return end data