Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checking atime causes problems if disk mounted with noatime #556

Open
taurgal opened this issue Sep 5, 2024 · 1 comment
Open

Checking atime causes problems if disk mounted with noatime #556

taurgal opened this issue Sep 5, 2024 · 1 comment

Comments

@taurgal
Copy link

taurgal commented Sep 5, 2024

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
Copy link
Author

taurgal commented Sep 9, 2024

In fact my code above did not work (got other cryptic errors). But the fix from
#464 (comment)
does work for me.

Digging a little bit I think the error is that in function jupyter-session-with-random-ports (in file jupyter-env.el) the lines

        (jupyter-with-timeout
            (nil jupyter-default-timeout
                 (delete-file conn-file))
          (file-exists-p conn-file))

should read

        (jupyter-with-timeout
            (nil jupyter-default-timeout
                 (delete-file conn-file))
          (not (file-exists-p conn-file)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant