improved reconnect to compensate for ARM wake times

This commit is contained in:
David Botton 2024-06-28 11:28:03 -04:00
parent 5dba6315ac
commit a894c739c8
3 changed files with 58 additions and 41 deletions

View file

@ -42,17 +42,21 @@
(handler-case
(cond ((and id (gethash id *connection-data*))
(format t "Reconnection id - ~A to ~A~%" id connection)
(let ((old (gethash id *connection-ids*)))
(when *verbose-output*
(format t "Transfer id - ~A => ~A" old connection))
(setf (gethash old *connections*) nil)
(setf (gethash connection *connections*) id)
(setf (gethash id *connection-ids*) connection)
(handler-case
(websocket-driver:close-connection (gethash id *connection-ids*)
(websocket-driver:close-connection old
"Aborting this old connection since receiving a reconnection request.")
(t (c)
(when *verbose-output*
(format t "Failed to close the old connection when establishing reconnection. ~
This can be normal: The old connection could not work for the client, ~
so the client is requesting to reconnect.~%Condition - ~A.~&"
c))))
(setf (gethash id *connection-ids*) connection)
(setf (gethash connection *connections*) id))
c))))))
(id
(format t "Reconnection id ~A not found. Closing the connection.~%" id)
(websocket-driver:close-connection connection)) ; Don't send the reason for better security.
@ -162,6 +166,14 @@
(defun handle-close-connection (connection)
"Close websocket CONNECTION. (Private)"
(when *verbose-output*
(format t "Connection close request ~A.~%"
connection))
(when *reconnect-delay*
(when *verbose-output*
(format t "Connection close request ~A delayed ~A for reconnects.~%"
connection *reconnect-delay*))
(sleep *reconnect-delay*))
(handler-case
(let ((id (gethash connection *connections*)))
(when id

View file

@ -38,6 +38,7 @@ script."
(*browser-gc-on-ping* variable)
(*break-on-error* variable)
(*disable-clog-debugging* variable)
(*reconnect-delay* variable)
(initialize function)
(random-port function)
@ -87,6 +88,7 @@ script."
(defvar *browser-gc-on-ping* nil "Run a browser-gc on every ping (default nil)")
(defvar *break-on-error* t "Allow invoking debugger (default t)")
(defvar *disable-clog-debugging* nil "When true turns off debug hooks (default nil)")
(defvar *reconnect-delay* 3 "Time to delay in seconds for possible reconnect (default 3)")
(defvar *on-connect-handler* nil "New connection event handler.")

View file

@ -84,14 +84,17 @@
(setf *editor-delay-on-eval-file* 60)
;; Server Settings
;; When true turns off debug hooks
;; when true turns off debug hooks
(setf clog-connection:*disable-clog-debugging* nil)
;; Verbose server output
;; verbose server output
(setf clog-connection:*verbose-output* nil)
;; Run a browser-gc on every ping
;; run a browser-gc on every ping
(setf clog-connection:*browser-gc-on-ping* nil)
;; Allow invoking debugger
;; allow invoking debugger
(setf clog-connection:*break-on-error* t)
;; time to delay for possible reconnect, such as after sleep or
;; long network latenacies.
(setf clog-connection:*reconnect-delay* 3)
;; CLOG Builder REPL
(setf *clog-repl-use-console* t)