jupyter icon indicating copy to clipboard operation
jupyter copied to clipboard

Checking atime causes problems if disk mounted with noatime

Open taurgal opened this issue 5 months ago • 1 comments

In jupyter-kernel-process.el function jupyter--start-kernel-process checks the connection file conn-file 's atime to avoid bugs where jupyter starts kernels using the same port in a loop.

Obviously this does not work if the disk as been mounted with noatime which is quite common with SSDs nowadays.

A quick fix is to use a boolean variable jupyter--use-conn-file-atime. On linux, parsing the output of mount or /proc/mounts would be cool...

Temporary fix (only change in jupyter--start-kernel-process is the (not (jupyter--use-conn-file-atime))) line:

 (defvar jupyter--use-conn-file-atime nil
    "Whether to use the access time of the connexion file to check kernel process start up")
(defun jupyter--start-kernel-process (name kernelspec conn-file)
  (let* ((process-name (format "jupyter-kernel-%s" name))
         (buffer-name (format " *jupyter-kernel[%s]*" name))
         (process-environment
          (append (jupyter-process-environment kernelspec)
                  process-environment))
         (args (jupyter-kernel-argv kernelspec conn-file))
         (atime (nth 4 (file-attributes conn-file)))
         (process (apply #'start-file-process process-name
                         (generate-new-buffer buffer-name)
                         (car args) (cdr args))))
    (set-process-query-on-exit-flag process jupyter--debug)
    ;; Wait until the connection file has been read before returning.
    ;; This is to give the kernel a chance to setup before sending it
    ;; messages.
    ;;
    ;; TODO: Replace with a check of the heartbeat channel.
    (jupyter-with-timeout
        ((format "Starting %s kernel process..." name)
         jupyter-long-timeout
         (unless (process-live-p process)
           (error "Kernel process exited:\n%s"
                  (with-current-buffer (process-buffer process)
                    (ansi-color-apply (buffer-string))))))
      ;; Windows systems may not have good time resolution when retrieving
      ;; the last access time of a file so we don't bother with checking that
      ;; the kernel has read the connection file and leave it to the
      ;; downstream initialization to ensure that we can communicate with a
      ;; kernel.
      (or (not (jupyter--use-conn-file-atime))
          (memq system-type '(ms-dos windows-nt cygwin))
          (let ((attribs (file-attributes conn-file)))
            ;; `file-attributes' can potentially return nil, in this case
            ;; just assume it has read the connection file so that we can
            ;; know for sure it is not connected if it fails to respond to
            ;; any messages we send it.
            (or (null attribs)
                (not (equal atime (nth 4 attribs)))))))
    (jupyter--gc-kernel-processes)
    (push (list process conn-file) jupyter--kernel-processes)
    process))```

taurgal avatar Sep 05 '24 12:09 taurgal