mirror of https://github.com/Desuuuu/klipper.git
webhooks: process request handlers using a Reactor Callback
This prevents _process_data from blocking and becoming reentrant. Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
65ade083b2
commit
bfbdc04c02
|
@ -98,7 +98,6 @@ class ServerConnection:
|
|||
# Klippy Connection
|
||||
self.fd = self.fd_handle = self.mutex = None
|
||||
self.is_server_connected = False
|
||||
self.is_busy = False
|
||||
self.partial_data = ""
|
||||
is_fileoutput = (printer.get_start_args().get('debugoutput')
|
||||
is not None)
|
||||
|
@ -151,29 +150,20 @@ class ServerConnection:
|
|||
requests = data.split('\x03')
|
||||
requests[0] = self.partial_data + requests[0]
|
||||
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:
|
||||
logging.debug(
|
||||
"ServerConnection: Request received from Moonraker %s" % (req))
|
||||
"ServerConnection: Request received: %s" % (req))
|
||||
try:
|
||||
decoded_req = json_loads_byteified(req)
|
||||
self._process_request(decoded_req)
|
||||
web_request = WebRequest(json_loads_byteified(req))
|
||||
except Exception:
|
||||
logging.exception(
|
||||
"ServerConnection: Error processing Server Request %s"
|
||||
"ServerConnection: Error decoding Server Request %s"
|
||||
% (req))
|
||||
self.is_busy = False
|
||||
if self.fd_handle is None:
|
||||
self.fd_handle = self.reactor.register_fd(
|
||||
self.fd, self.process_received)
|
||||
continue
|
||||
self.reactor.register_callback(
|
||||
lambda e, s=self: s._process_request(web_request))
|
||||
|
||||
def _process_request(self, req):
|
||||
web_request = WebRequest(req)
|
||||
def _process_request(self, web_request):
|
||||
try:
|
||||
func = self.webhooks.get_callback(
|
||||
web_request.get_path())
|
||||
|
|
Loading…
Reference in New Issue