svaante / dape

Debug Adapter Protocol for Emacs
GNU General Public License v3.0
455 stars 25 forks source link

launching timeout should not kill debug session #32

Closed alan-w-255 closed 9 months ago

alan-w-255 commented 9 months ago

https://github.com/svaante/dape/blob/a8e56d3767e1b063f6c49a6081ca4e22afdfaaaf/dape.el#L962C21-L962C21

Launch a debug session can take a quite long time.

And the error message don't tell user what cause the debug session fail, it confuse user when debug session quit causing by timeout.

svaante commented 9 months ago

Do you not get the printout from?

                     (dape--repl-message msg 'dape-repl-exit-code-fail)

The adapters are never killed due to timeout unless you count connection timeout (if you don't count the host and port not being open). I still think it makes sense to kill the debugger on a failed launch/attach, but there is an known issue that is on my todo is that server stdout/stderr is not printed unless it sends a valid package.

Could you please share your configuration and setup so I can take a closer look.

alan-w-255 commented 9 months ago
(defun dape--create-timer (process seq)
  "Create SEQ request timeout timer for PROCESS."
  (puthash seq
           (run-with-timer dape--timeout
                           nil
                           (dape--callback
                            (dape--debug 'error
                                         "Timeout for reached for seq %d"
                                         seq)
                            (when (dape--live-process t)
                              (dape--update-state "timed out"))
                            (remhash seq dape--timers)
                            (when-let ((cb (gethash seq dape--cb)))
                              (remhash seq dape--cb)
                              (funcall cb process nil nil nil)))
                           process)
           dape--timers))
(defun dape-request (process command arguments &optional cb)
  "Send request COMMAND to PROCESS with ARGUMENTS.
If CB set, invoke CB on response.
See `dape--callback' for expected function signature."
  (let ((seq (setq dape--seq (1+ dape--seq)))
        (object (and arguments (list :arguments arguments))))
    (dape--create-timer process seq) ;; the timer
    (when cb
      (puthash seq cb dape--cb))
    (dape-send-object process
                      seq
                      (thread-first object
                                    (plist-put :type "request")
                                    (plist-put :command command)))))

The dape--create-timer funcall the callback of the request. And the (dape--repl-message msg 'dape-repl-exit-code-fail) did not print any thing in the dape-repl buffer.

After i increase the dape--timeout to a large number or just remove the (dape-kill), the issue is gone.

i am just using the built-in dlv debug config:

(dlv
     modes (go-mode go-ts-mode)
     ensure dape-ensure-command
     fn dape-config-autoport
     command "dlv"
     command-args ("dap" "--listen" "127.0.0.1::autoport")
     command-cwd dape-cwd-fn
     port :autoport
     :request "launch"
     :type "debug"
     :cwd dape-cwd-fn
     :program dape-cwd-fn)
svaante commented 9 months ago

Would you mind sharing your dape-debug buffer contents without your changes. And also with your changes.

What I am guess is happening is that a startup is longer then 5 seconds then the request is ignored.

alan-w-255 commented 9 months ago

I currently do not have a large Go project at hand that requires lengthy compilation, so I used a small Go project and set dape--timeout to 0.1 to simulate a timeout scenario. Below is the output from the *dape-debug* buffer log. (The code used is from the master branch, with no modifications.)

[info] Starting new multi session with config:
(modes (go-mode go-ts-mode) ensure dape-ensure-command fn dape-config-autoport command "dlv" command-args ("dap" "--listen" "127.0.0.1:37981") command-cwd "/home/alan/Document/practise/learngo/" port 37981 :request "launch" :type "debug" :cwd "/home/alan/Document/practise/learngo/" :program "/home/alan/Document/practise/learngo/")
[info] Server process started ("dlv" "dap" "--listen" "127.0.0.1:37981")
[std-server] Server stdout:
DAP server listening at: 127.0.0.1:37981

[info] Connection to server established localhost:37981
[io] Sending:
(:arguments (:clientID "dape" :adapterID "debug" :pathFormat "path" :linesStartAt1 t :columnsStartAt1 t :supportsRunInTerminalRequest t :supportsProgressReporting t :supportsStartDebuggingRequest t) :type "request" :command "initialize" :seq 1)
[io] Received:
(:seq 0 :type "response" :request_seq 1 :success t :command "initialize" :body (:supportsConfigurationDoneRequest t :supportsFunctionBreakpoints t :supportsConditionalBreakpoints t :supportsEvaluateForHovers t :supportsSetVariable t :supportsExceptionInfoRequest t :supportsDelayedStackTraceLoading t :supportsLogPoints t :supportsDisassembleRequest t :supportsClipboardContext t :supportsSteppingGranularity t :supportsInstructionBreakpoints t))
[io] Sending:
(:arguments (:request "launch" :type "debug" :cwd "/home/alan/Document/practise/learngo/" :program "/home/alan/Document/practise/learngo/") :type "request" :command "launch" :seq 2)
[error] Timeout for reached for seq 2
[io] Sending:
(:arguments (:restart nil) :type "request" :command "disconnect" :seq 3)
[io] Received:
(:seq 0 :type "event" :event "initialized")
[io] Sending:
(:arguments (:source (:name "main.go" :path "/home/alan/Document/practise/learngo/main.go") :breakpoints [(:line 8)] :lines [8]) :type "request" :command "setBreakpoints" :seq 4)
[io] Received:
(:seq 0 :type "response" :request_seq 2 :success t :command "launch")
[io] Received:
(:seq 0 :type "event" :event "output" :body (:category "console" :output "Detaching and terminating target process
"))
[error] Timeout for reached for seq 3
[io] Flushing io buffer:

[info] 
Process nil exited with 0
[io] Flushing io buffer:

[info] 
Process ("dlv" "dap" "--listen" "127.0.0.1:37981") exited with 9

Here is the log output from the *dape-debug* buffer when dape--timeout is set to the default 5 seconds and dape starts normally.

[info] Starting new multi session with config:
(modes (go-mode go-ts-mode) ensure dape-ensure-command fn dape-config-autoport command "dlv" command-args ("dap" "--listen" "127.0.0.1:39173") command-cwd "/home/alan/Document/practise/learngo/" port 39173 :request "launch" :type "debug" :cwd "/home/alan/Document/practise/learngo/" :program "/home/alan/Document/practise/learngo/")
[info] Server process started ("dlv" "dap" "--listen" "127.0.0.1:39173")
[std-server] Server stdout:
DAP server listening at: 127.0.0.1:39173

[info] Connection to server established localhost:39173
[io] Sending:
(:arguments (:clientID "dape" :adapterID "debug" :pathFormat "path" :linesStartAt1 t :columnsStartAt1 t :supportsRunInTerminalRequest t :supportsProgressReporting t :supportsStartDebuggingRequest t) :type "request" :command "initialize" :seq 1)
[io] Received:
(:seq 0 :type "response" :request_seq 1 :success t :command "initialize" :body (:supportsConfigurationDoneRequest t :supportsFunctionBreakpoints t :supportsConditionalBreakpoints t :supportsEvaluateForHovers t :supportsSetVariable t :supportsExceptionInfoRequest t :supportsDelayedStackTraceLoading t :supportsLogPoints t :supportsDisassembleRequest t :supportsClipboardContext t :supportsSteppingGranularity t :supportsInstructionBreakpoints t))
[io] Sending:
(:arguments (:request "launch" :type "debug" :cwd "/home/alan/Document/practise/learngo/" :program "/home/alan/Document/practise/learngo/") :type "request" :command "launch" :seq 2)
[io] Received:
(:seq 0 :type "event" :event "initialized")
[io] Sending:
(:arguments (:source (:name "main.go" :path "/home/alan/Document/practise/learngo/main.go") :breakpoints [(:line 8)] :lines [8]) :type "request" :command "setBreakpoints" :seq 3)
[io] Received:
(:seq 0 :type "response" :request_seq 2 :success t :command "launch")
[io] Received:
(:seq 0 :type "response" :request_seq 3 :success t :command "setBreakpoints" :body (:breakpoints [(:id 1 :verified t :source (:name "main.go" :path "/home/alan/Document/practise/learngo/main.go") :line 8)]))
[io] Sending:
(:type "request" :command "configurationDone" :seq 4)
[io] Received:
(:seq 0 :type "event" :event "output" :body (:category "console" :output "Type 'dlv help' for list of commands.
"))
[io] Received:
(:seq 0 :type "response" :request_seq 4 :success t :command "configurationDone")
[io] Received:
(:seq 0 :type "event" :event "stopped" :body (:reason "breakpoint" :threadId 1 :allThreadsStopped t :hitBreakpointIds [1]))
[io] Sending:
(:type "request" :command "threads" :seq 5)
[io] Received:
(:seq 0 :type "response" :request_seq 5 :success t :command "threads" :body (:threads [(:id 1 :name "* [Go 1] main.main (Thread 95200)") (:id 2 :name "[Go 2] runtime.gopark") (:id 3 :name "[Go 3] runtime.gopark") (:id 4 :name "[Go 4] runtime.gopark") (:id 5 :name "[Go 5] runtime.runfinq")]))
[io] Sending:
(:arguments (:threadId 1 :levels 50) :type "request" :command "stackTrace" :seq 6)
[io] Received:
(:seq 0 :type "response" :request_seq 6 :success t :command "stackTrace" :body (:stackFrames [(:id 1000 :name "main.main" :source (:name "main.go" :path "/home/alan/Document/practise/learngo/main.go") :line 8 :column 0 :instructionPointerReference "0x495c5a") (:id 1001 :name "runtime.main" :source (:name "proc.go" :path "/usr/lib/go/src/runtime/proc.go") :line 267 :column 0 :instructionPointerReference "0x43a0a7" :presentationHint "subtle") (:id 1002 :name "runtime.goexit" :source (:name "asm_amd64.s" :path "/usr/lib/go/src/runtime/asm_amd64.s") :line 1650 :column 0 :instructionPointerReference "0x465761" :presentationHint "subtle")] :totalFrames 3))
[io] Sending:
(:arguments (:frameId 1000) :type "request" :command "scopes" :seq 7)
[io] Received:
(:seq 0 :type "response" :request_seq 7 :success t :command "scopes" :body (:scopes [(:name "Locals" :variablesReference 1000 :expensive nil)]))
svaante commented 9 months ago

Does the latest commit solve your problem?

alan-w-255 commented 9 months ago

Thank you for your patience and your great work. It works perfectly on my machine. 👍