Skip to content

Commit

Permalink
#15: time-outed connection is ok when cleaning DB session.
Browse files Browse the repository at this point in the history
  • Loading branch information
garncarz committed Nov 17, 2018
1 parent 2ed6e7e commit e400804
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions nogamespy/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import socketserver
import struct

from pymysql.err import OperationalError

import aluigi
from . import models, tasks, settings
from .database import db_session
Expand Down Expand Up @@ -60,8 +62,12 @@ class MasterHandler(socketserver.BaseRequestHandler):
def handle(self):
logger.debug(f'Responding to {self.request.getpeername()[0]}...')

# so we're not stuck in a previous invalid transaction
db_session.remove()
try:
# so we're not stuck in a previous invalid transaction
db_session.remove()
except OperationalError:
# connection can be time-outed
pass

self.request.sendall('\\basic\\\\secure\\'.encode('latin1'))
self.request.send(get_encoded_server_list())
Expand All @@ -82,8 +88,12 @@ class HeartbeatHandler(socketserver.BaseRequestHandler):
def handle(self):
logger.debug(f'Got heartbeat from {self.client_address[0]}...')

# so we're not stuck in a previous invalid transaction
db_session.remove()
try:
# so we're not stuck in a previous invalid transaction
db_session.remove()
except OperationalError:
# connection can be time-outed
pass

msg = self.request[0].decode('ascii').split('\\')

Expand Down

0 comments on commit e400804

Please sign in to comment.