Skip to content

Commit

Permalink
Null check in websocket callbacks
Browse files Browse the repository at this point in the history
Forestall worrisome errback calls when websocket flatlines.
  • Loading branch information
dickmao committed Oct 21, 2020
1 parent 12b5c1c commit fbc1d99
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lisp/ein-gat.el
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ With WORKTREE-DIR of /home/dick/gat/test-repo2
(magit-with-editor
(let* ((dockerfile (format "Dockerfile.%s" (file-name-sans-extension notebook)))
(base-image (ein:gat-elicit-base-image))
(_ (with-temp-file dockerfile (insert (format "FROM %s\nCOPY ./%s .\nCMD [ \"start.sh\", \"jupyter\", \"nbconvert\", \"--ExecutePreprocessor.timeout=21600\", \"--to\", \"notebook\", \"--execute\", \"%s\" ]" base-image notebook notebook))))
(_ (with-temp-file dockerfile (insert (format "FROM %s\nCOPY --chown=jovyan:users ./%s .\nCMD [ \"start.sh\", \"jupyter\", \"nbconvert\", \"--ExecutePreprocessor.timeout=21600\", \"--to\", \"notebook\", \"--execute\", \"%s\" ]" base-image notebook notebook))))
(my-editor (when (and (boundp 'server-name)
(server-running-p server-name))
`("-s" ,server-name))))
Expand Down
31 changes: 16 additions & 15 deletions lisp/ein-kernel.el
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ See https://github.com/ipython/ipython/pull/3307"
(ein:websocket-send channel cookie)))

(defun ein:kernel--handle-websocket-reply (kernel _ws frame)
(ein:and-let* ((packet (websocket-frame-payload frame))
(channel (plist-get (ein:json-read-from-string packet) :channel)))
(-when-let* ((packet (websocket-frame-payload frame))
(channel (plist-get (ein:json-read-from-string packet) :channel)))
(cond ((string-equal channel "iopub")
(ein:kernel--handle-iopub-reply kernel packet))
((string-equal channel "shell")
Expand All @@ -289,21 +289,22 @@ See https://github.com/ipython/ipython/pull/3307"
(ein:websocket ws-url kernel
(apply-partially #'ein:kernel--handle-websocket-reply kernel)
(lambda (ws)
(let* ((websocket (websocket-client-data ws))
(kernel (ein:$websocket-kernel websocket)))
(unless (ein:$websocket-closed-by-client websocket)
(ein:log 'verbose "WS closed unexpectedly: %s" (websocket-url ws))
(ein:kernel-disconnect kernel))))
(-if-let* ((websocket (websocket-client-data ws))
(kernel (ein:$websocket-kernel websocket)))
(unless (ein:$websocket-closed-by-client websocket)
(ein:log 'verbose "WS closed unexpectedly: %s" (websocket-url ws))
(ein:kernel-disconnect kernel))
(ein:log 'error "ein:start-single-websocket: on-close no client data for %s." ws)))
(apply-partially
(lambda (cb ws)
(let* ((websocket (websocket-client-data ws))
(kernel (ein:$websocket-kernel websocket)))
(when (ein:kernel-live-p kernel)
(ein:log 'debug "ein:start-single-websocket: Running on-connect abnormal hooks.")
(run-hook-with-args 'ein:on-kernel-connect-functions kernel)
(when cb
(funcall cb kernel)))
(ein:log 'verbose "WS opened: %s" (websocket-url ws))))
(-if-let* ((websocket (websocket-client-data ws))
(kernel (ein:$websocket-kernel websocket)))
(progn
(when (ein:kernel-live-p kernel)
(run-hook-with-args 'ein:on-kernel-connect-functions kernel)
(when cb (funcall cb kernel)))
(ein:log 'verbose "WS opened: %s" (websocket-url ws)))
(ein:log 'error "ein:start-single-websocket: on-open no client data for %s." ws)))
open-callback)))))

(defun ein:kernel-start-websocket (kernel callback)
Expand Down

0 comments on commit fbc1d99

Please sign in to comment.