Fix regression with idle_timout not correctly closing connection. Fix errors due to Portal and Server trying to send to non-existing sessions after connection closes.

This commit is contained in:
Griatch 2016-09-14 19:07:59 +02:00
parent 2737d37633
commit 67411d006d
2 changed files with 7 additions and 3 deletions

View file

@ -435,7 +435,9 @@ class AMPProtocol(amp.AMP):
"""
sessid, kwargs = loads(packed_data)
self.factory.server.sessions.data_in(self.factory.server.sessions[sessid], **kwargs)
session = self.factory.server.sessions.get(sessid, None)
if session:
self.factory.server.sessions.data_in(session, **kwargs)
return {}
def send_MsgPortal2Server(self, session, **kwargs):
@ -464,7 +466,9 @@ class AMPProtocol(amp.AMP):
packed_data (str): Pickled data (sessid, kwargs) coming over the wire.
"""
sessid, kwargs = loads(packed_data)
self.factory.portal.sessions.data_out(self.factory.portal.sessions[sessid], **kwargs)
session = self.factory.portal.sessions.get(sessid, None)
if session:
self.factory.portal.sessions.data_out(session, **kwargs)
return {}

View file

@ -87,7 +87,7 @@ def _portal_maintenance():
reason = "Idle timeout exceeded, disconnecting."
for session in [sess for sess in PORTAL_SESSIONS.values()
if (now - sess.cmd_last) > _IDLE_TIMEOUT]:
session.data_out(text=[[reason], {}])
session.disconnect(reason=reason)
PORTAL_SESSIONS.disconnect(session)
if _IDLE_TIMEOUT > 0: