diff options
author | Teddy Wing | 2021-02-14 19:52:32 +0100 |
---|---|---|
committer | Teddy Wing | 2021-02-14 19:52:32 +0100 |
commit | 94265081b0efdd13ab480032547d2ac1f76daf83 (patch) | |
tree | 315922c0bfefc1cdb24bbcae953ddef2a21d8fc0 /l/src/main.lisp | |
parent | 5baf8d91fc8450cc5e9639fab25a01c432986b7b (diff) | |
download | extreload-94265081b0efdd13ab480032547d2ac1f76daf83.tar.bz2 |
Timeout after five seconds
Set a five second timeout to ensure we don't block endlessly if we send
a WebSocket message and don't receive a response in a reasonable amount
of time.
Chose five seconds arbitrarily, but that seems like more than enough
time to do our work. If it takes longer, something else is probably
wrong.
Diffstat (limited to 'l/src/main.lisp')
-rw-r--r-- | l/src/main.lisp | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/l/src/main.lisp b/l/src/main.lisp index 641255b..0695f20 100644 --- a/l/src/main.lisp +++ b/l/src/main.lisp @@ -6,6 +6,8 @@ (defvar *extension-targets-count* 0) (defvar *last-session-id* "") +(defconstant +timeout-seconds+ 5) + (opts:define-opts (:name :socket-url :description "DevTools protocol WebSocket URL" @@ -32,18 +34,19 @@ ;; Store the WebSocket client as a global. (defvar *client* (ws-client config)) - (with-websocket-connection (*client*) - (wsd:on :message *client* - #'(lambda (message) - (ws-on-message - message - (extension-ids config) - (reload-current-tab config)))) + (trivial-timeout:with-timeout (+timeout-seconds+) + (with-websocket-connection (*client*) + (wsd:on :message *client* + #'(lambda (message) + (ws-on-message + message + (extension-ids config) + (reload-current-tab config)))) - (websocket-send *client* (target-get-targets-msg - (next-call-id *devtools-root-call-id*))) + (websocket-send *client* (target-get-targets-msg + (next-call-id *devtools-root-call-id*))) - (wait-group:wait *wg*))))) + (wait-group:wait *wg*)))))) (defun ws-on-message (message extension-ids reload-current-tab) (let* ((response (jsown:parse message)) |