webhooks: protect command processing from re-entry
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
a342770ac5
commit
2d2c09a0a3
|
@ -97,8 +97,9 @@ class ServerConnection:
|
||||||
self.reactor = printer.get_reactor()
|
self.reactor = printer.get_reactor()
|
||||||
|
|
||||||
# Klippy Connection
|
# Klippy Connection
|
||||||
self.fd_handler = self.mutex = None
|
self.fd = self.fd_handle = self.mutex = None
|
||||||
self.is_server_connected = False
|
self.is_server_connected = False
|
||||||
|
self.is_busy = False
|
||||||
self.partial_data = ""
|
self.partial_data = ""
|
||||||
is_fileoutput = (printer.get_start_args().get('debugoutput')
|
is_fileoutput = (printer.get_start_args().get('debugoutput')
|
||||||
is not None)
|
is not None)
|
||||||
|
@ -115,8 +116,9 @@ class ServerConnection:
|
||||||
return
|
return
|
||||||
logging.debug("ServerConnection: Moonraker connection established")
|
logging.debug("ServerConnection: Moonraker connection established")
|
||||||
self.is_server_connected = True
|
self.is_server_connected = True
|
||||||
self.fd_handler = self.reactor.register_fd(
|
self.fd = self.socket.fileno()
|
||||||
self.socket.fileno(), self.process_received)
|
self.fd_handle = self.reactor.register_fd(
|
||||||
|
self.fd, self.process_received)
|
||||||
self.mutex = self.reactor.mutex()
|
self.mutex = self.reactor.mutex()
|
||||||
printer.register_event_handler('klippy:disconnect', self.close_socket)
|
printer.register_event_handler('klippy:disconnect', self.close_socket)
|
||||||
|
|
||||||
|
@ -124,7 +126,7 @@ class ServerConnection:
|
||||||
if self.is_server_connected:
|
if self.is_server_connected:
|
||||||
logging.info("ServerConnection: lost connection to Moonraker")
|
logging.info("ServerConnection: lost connection to Moonraker")
|
||||||
self.is_server_connected = False
|
self.is_server_connected = False
|
||||||
self.reactor.unregister_fd(self.fd_handler)
|
self.reactor.unregister_fd(self.fd_handle)
|
||||||
try:
|
try:
|
||||||
self.socket.close()
|
self.socket.close()
|
||||||
except socket.error:
|
except socket.error:
|
||||||
|
@ -150,6 +152,12 @@ class ServerConnection:
|
||||||
requests = data.split('\x03')
|
requests = data.split('\x03')
|
||||||
requests[0] = self.partial_data + requests[0]
|
requests[0] = self.partial_data + requests[0]
|
||||||
self.partial_data = requests.pop()
|
self.partial_data = requests.pop()
|
||||||
|
if self.is_busy:
|
||||||
|
if len(requests > 20):
|
||||||
|
self.reactor.unregister_fd(self.fd_handle)
|
||||||
|
self.fd_handle = None
|
||||||
|
return
|
||||||
|
self.is_busy = True
|
||||||
for req in requests:
|
for req in requests:
|
||||||
logging.debug(
|
logging.debug(
|
||||||
"ServerConnection: Request received from Moonraker %s" % (req))
|
"ServerConnection: Request received from Moonraker %s" % (req))
|
||||||
|
@ -160,6 +168,10 @@ class ServerConnection:
|
||||||
logging.exception(
|
logging.exception(
|
||||||
"ServerConnection: Error processing Server Request %s"
|
"ServerConnection: Error processing Server Request %s"
|
||||||
% (req))
|
% (req))
|
||||||
|
self.is_busy = False
|
||||||
|
if self.fd_handle is None:
|
||||||
|
self.fd_handle = self.reactor.register_fd(
|
||||||
|
self.fd, self.process_received)
|
||||||
|
|
||||||
def _process_request(self, req):
|
def _process_request(self, req):
|
||||||
web_request = WebRequest(req)
|
web_request = WebRequest(req)
|
||||||
|
|
Loading…
Reference in New Issue