phoityne / haskell-debug-adapter

Debug Adapter for Haskell debugging system.
https://hackage.haskell.org/package/haskell-debug-adapter
BSD 3-Clause "New" or "Revised" License
53 stars 8 forks source link

Invalid dap result from ghci #18

Open malte-v opened 4 years ago

malte-v commented 4 years ago

Hey there, thanks for making this extension! I'm having some trouble getting it to work.

My app is a warp server that is accessed from a web browser. I'm able start debugging without any problems:

Configuration read.
Starting GHCi.
Wait for a moment.

CWD: /home/malte/testing/reflex-stack
CMD: stack ghci --with-ghc=ghci-dap --test --no-load --no-build --main-is app --ghci-options -fprint-evld-with-show

Now, waiting for an initial prompt("> ") from ghci.

Configuring GHCi with the following packages: app, backend, common, frontend
[DAP][INFO] start ghci-dap-0.0.14.0.
GHCi, version 8.8.3: https://www.haskell.org/ghc/  :? for help
>:set prompt "<<DAP_CMD_END2>>\nH>>= "
H>>= :set prompt-cont "<<DAP_CMD_END2>>\nH>>= "
H>>= :dap-launch ...
H>>= :load /home/malte/testing/reflex-stack/app/Main.hs
[1 of 6] Compiling Common.API       ( /home/malte/testing/reflex-stack/common/src/Common/API.hs, interpreted )
[2 of 6] Compiling Backend          ( /home/malte/testing/reflex-stack/backend/src/Backend.hs, interpreted )
[3 of 6] Compiling Frontend.API     ( /home/malte/testing/reflex-stack/frontend/src/Frontend/API.hs, interpreted )
[4 of 6] Compiling Frontend.Router  ( /home/malte/testing/reflex-stack/frontend/src/Frontend/Router.hs, interpreted )
[5 of 6] Compiling Frontend         ( /home/malte/testing/reflex-stack/frontend/src/Frontend.hs, interpreted )
[6 of 6] Compiling Main             ( /home/malte/testing/reflex-stack/app/Main.hs, interpreted )
Ok, six modules loaded.
H>>= :dap-context-modules ...
H>>= :dap-set-function-breakpoints ...
H>>= :set -fno-break-on-exception
H>>= :set -fno-break-on-error
H>>= :dap-continue ...
Running on https://localhost:8080

... but when my app gets an HTTPS request from the browser, the debugger exits with the following message:

Running on https://localhost:8080 ^^^ from above
[CRITICAL][APP] invalid dap result from ghci. ["Running on https://localhost:8080"]

Here are the contents of the log file and my launch.json:

2020-07-02 15:40:22.642090197000 [43274(ThreadId 9)] CRITICAL APP - invalid dap result from ghci. ["Running on https://localhost:8080"]
2020-07-02 15:40:23.087097425000 [43274(ThreadId 12)] CRITICAL THREAD_MGR - Critical exit started.
{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "type": "ghc",
      "request": "launch",
      "name": "Haskell",
      "internalConsoleOptions": "openOnSessionStart",
      "workspace": "${workspaceFolder}",
      "startup": "${workspaceFolder}/app/Main.hs",
      "startupFunc": "",
      "startupArgs": "",
      "stopOnEntry": false,
      "mainArgs": "",
      "ghciPrompt": "H>>= ",
      "ghciInitialPrompt": "> ",
      "ghciCmd": "stack ghci --test --no-load --no-build --main-is app --ghci-options -fprint-evld-with-show",
      "ghciEnv": {},
      "logFile": "${workspaceFolder}/.vscode/debugger.log",
      "logLevel": "WARNING",
      "forceInspect": false
    }
  ]
}

I've tried not printing the "Running on https://localhost:8080" message, but then I get the following error after reloading the browser:

[CRITICAL][APP] invalid dap result from ghci. []

So I don't think this is the culprit. I've installed these versions of the tools mentioned in the VSCode extension README:

➜  ~ ghci-dap --version
[DAP][INFO] start ghci-dap-0.0.14.0.
The Glorious Glasgow Haskell Compilation System, version 8.8.3
➜  ~ haskell-debug-adapter --version
haskell-debug-adapter-0.0.33.0

Any idea what could have gone wrong here? Thanks!

phoityne commented 4 years ago

Hi.

[CRITICAL][APP] invalid dap result from ghci. []

This seems that haskell-debug-adapter lost stdio handle to ghci-dap.

Could you run these commands from the console? and let me know the console result.

> cd /home/malte/testing/reflex-stack
> stack ghci --with-ghc=ghci-dap --test --no-load --no-build --main-is app --ghci-options -fprint-evld-with-show
...
...
Prelude> :load /home/malte/testing/reflex-stack/app/Main.hs
Prelude> :trace main
...
...
gets an HTTPS request from the browser.

I tried to reproduce with a servant app, but could't.

malte-v commented 4 years ago
➜  reflex-stack git:(master) ✗ stack ghci --with-ghc=ghci-dap --test --no-load --no-build --main-is app --ghci-options -fprint-evld-with-show
Configuring GHCi with the following packages: app, backend, common, frontend
[DAP][INFO] start ghci-dap-0.0.14.0.
GHCi, version 8.8.3: https://www.haskell.org/ghc/  :? for help
> :load /home/malte/testing/reflex-stack/app/Main.hs
[1 of 6] Compiling Common.API       ( /home/malte/testing/reflex-stack/common/src/Common/API.hs, interpreted )
[2 of 6] Compiling Backend          ( /home/malte/testing/reflex-stack/backend/src/Backend.hs, interpreted )
[3 of 6] Compiling Frontend.API     ( /home/malte/testing/reflex-stack/frontend/src/Frontend/API.hs, interpreted )
[4 of 6] Compiling Frontend.Router  ( /home/malte/testing/reflex-stack/frontend/src/Frontend/Router.hs, interpreted )
[5 of 6] Compiling Frontend         ( /home/malte/testing/reflex-stack/frontend/src/Frontend.hs, interpreted )
[6 of 6] Compiling Main             ( /home/malte/testing/reflex-stack/app/Main.hs, interpreted )
Ok, six modules loaded.
*Main> :trace main
Running on https://localhost:8080
# gets HTTPS request
[1]    20518 segmentation fault (core dumped)  stack ghci --with-ghc=ghci-dap --test --no-load --no-build --main-is app

Here is the code, if you want to try to reproduce the issue: https://github.com/malte-v/reflex-stack/tree/739f8bd8466c65be9e6ae75ce3a3acf65a22690a As stated in the README, you need to run tools/certify. It's ok to just always press enter when it asks for information. You also can skip adding the CA to your browser and just dismiss the usual warning about the invalid certificate. Thanks for looking into this!

malte-v commented 4 years ago

This seems to be SSL-specific, which is probably why you couldn't reproduce the issue:

➜  ~ curl -v --insecure https://localhost:8080                                                         
*   Trying ::1:8080...
* connect to ::1 port 8080 failed: Connection refused
*   Trying 127.0.0.1:8080...
* Connected to localhost (127.0.0.1) port 8080 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: none
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to localhost:8080 
* Closing connection 0
curl: (35) OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to localhost:8080 

When running regularly (not inside the debugger):

➜  ~ curl -v --insecure https://localhost:8080
*   Trying ::1:8080...
* connect to ::1 port 8080 failed: Connection refused
*   Trying 127.0.0.1:8080...
* Connected to localhost (127.0.0.1) port 8080 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: none
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
* TLSv1.3 (IN), TLS handshake, Finished (20):
* TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.3 (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
* ALPN, server accepted to use h2
* Server certificate:
*  subject: C=AU; ST=Some-State; O=self-signed localhost certificate
*  start date: Jul  1 16:51:37 2020 GMT
*  expire date: Oct  4 16:51:37 2022 GMT
*  issuer: C=AU; ST=Some-State; O=malte
*  SSL certificate verify result: unable to get local issuer certificate (20), continuing anyway.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x563291dc78b0)
> GET / HTTP/2
> Host: localhost:8080
> user-agent: curl/7.70.0
> accept: */*
> 
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* Connection state changed (MAX_CONCURRENT_STREAMS == 100)!
< HTTP/2 200 
< date: Fri, 03 Jul 2020 14:03:54 GMT
< server: Warp/3.3.12
< content-type: text/html
< 
<!DOCTYPE html>
<html>
<head>
<title>JSaddle</title>
</head>
<body>
</body>
<script src="/jsaddle.js"></script>
</html>
* Connection #0 to host localhost left intact
malte-v commented 4 years ago

I can confirm that the issue does not occur when using HTTP.

phoityne commented 4 years ago

What is your OS environment ? Could you run these commands from console ? (without ghci-dap, running original ghci.)

> cd /home/malte/testing/reflex-stack
> stack ghci --test --no-load --no-build --main-is app --ghci-options -fprint-evld-with-show
...
...
Prelude> :load /home/malte/testing/reflex-stack/app/Main.hs
Prelude> :trace main
...
...
gets an HTTPS request from the browser.

Regards.