Improved error handling.
This commit is contained in:
parent
c1076e3856
commit
8b406e6d52
1 changed files with 15 additions and 8 deletions
|
@ -54,8 +54,9 @@ EventMachine.run {
|
||||||
|
|
||||||
if !@clients.include? client_id
|
if !@clients.include? client_id
|
||||||
@clients[client_id] = {
|
@clients[client_id] = {
|
||||||
:websocket => ws,
|
:websocket => ws,
|
||||||
:last_ping => Time.new
|
:last_ping => Time.new,
|
||||||
|
:error_count => 0,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
@ -85,6 +86,9 @@ EventMachine.run {
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# check if connection already exists
|
||||||
|
next if !@clients[client_id]
|
||||||
|
|
||||||
# get session
|
# get session
|
||||||
if data['action'] == 'login'
|
if data['action'] == 'login'
|
||||||
@clients[client_id][:session] = data['session']
|
@clients[client_id][:session] = data['session']
|
||||||
|
@ -102,14 +106,14 @@ EventMachine.run {
|
||||||
EventMachine.add_periodic_timer(120) {
|
EventMachine.add_periodic_timer(120) {
|
||||||
log 'notice', "check unused idle connections..."
|
log 'notice', "check unused idle connections..."
|
||||||
@clients.each { |client_id, client|
|
@clients.each { |client_id, client|
|
||||||
if ( @clients[client_id][:last_ping] + ( 60 * 4 ) ) < Time.now
|
if ( client[:last_ping] + ( 60 * 4 ) ) < Time.now
|
||||||
log 'notice', "closing idle connection", client_id
|
log 'notice', "closing idle connection", client_id
|
||||||
|
|
||||||
# remember to not use this connection anymore
|
# remember to not use this connection anymore
|
||||||
@clients[client_id][:disconnect] = true
|
client[:disconnect] = true
|
||||||
|
|
||||||
# try to close regular
|
# try to close regular
|
||||||
@clients[client_id][:websocket].close_websocket
|
client[:websocket].close_websocket
|
||||||
|
|
||||||
# delete sesstion from client list
|
# delete sesstion from client list
|
||||||
sleep 1
|
sleep 1
|
||||||
|
@ -129,7 +133,7 @@ EventMachine.run {
|
||||||
next if @clients.size == 0
|
next if @clients.size == 0
|
||||||
log 'debug', "checking for data..."
|
log 'debug', "checking for data..."
|
||||||
@clients.each { |client_id, client|
|
@clients.each { |client_id, client|
|
||||||
next if @clients[client_id][:disconnect]
|
next if client[:disconnect]
|
||||||
log 'debug', 'checking for data...', client_id
|
log 'debug', 'checking for data...', client_id
|
||||||
begin
|
begin
|
||||||
queue = Session.queue( client_id )
|
queue = Session.queue( client_id )
|
||||||
|
@ -143,8 +147,11 @@ EventMachine.run {
|
||||||
log 'error', 'problem:' + e.inspect, client_id
|
log 'error', 'problem:' + e.inspect, client_id
|
||||||
|
|
||||||
# disconnect client
|
# disconnect client
|
||||||
if @clients.include? client_id
|
client[:error_count] += 1
|
||||||
@clients.delete client_id
|
if client[:error_count] > 100
|
||||||
|
if @clients.include? client_id
|
||||||
|
@clients.delete client_id
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue