Skip to content

Segfault when running hls with TH and libpq #1982

Closed
@aschmois

Description

@aschmois

Your environment

Output of haskell-language-server --probe-tools or haskell-language-server-wrapper --probe-tools:

haskell-language-server-wrapper --probe-tools
haskell-language-server version: 1.1.0.0 (GHC: 8.10.4) (PATH: /home/andres/.ghcup/bin/haskell-language-server-wrapper-1.1.0) (GIT hash: f1c096927186a93d8e3ccd4fe8385cc1b070350b)
Tool versions found on the $PATH
cabal:          3.4.0.0
stack:          2.7.1
ghc:            8.10.4

Which OS do you use:
Ubuntu 20.04

Which lsp-client do you use:
VS Code (but irrelevant to the problem)

Describe your project (alternative: link to the project):
https://github.com/aschmois/th-pq-segfault

Steps to reproduce

Run haskell-language-server-wrapper

Expected behaviour

Completed hls command

Actual behaviour

Segfault exit

Include debug information

Execute in the root of your project the command haskell-language-server --debug . and paste the logs here:

Debug output:
haskell-language-server-wrapper --debug
Found "/home/foo/projects/example/hie.yaml" for "/home/foo/projects/example/a"
Module "/home/foo/projects/example/a" is loaded by Cradle: Cradle {cradleRootDir = "/home/foo/projects/example", cradleOptsProg = CradleAction: Stack}
Run entered for haskell-language-server-wrapper(haskell-language-server-wrapper) Version 1.1.0.0, Git revision f1c096927186a93d8e3ccd4fe8385cc1b070350b (dirty) x86_64 ghc-8.10.4
Current directory: /home/foo/projects/example
Operating system: linux
Arguments: ["--debug"]
Cradle directory: /home/foo/projects/example
Cradle type: Stack

Tool versions found on the $PATH
cabal:          3.4.0.0
stack:          2.7.1
ghc:            8.10.4


Consulting the cradle to get project GHC version...
Project GHC version: 8.10.4
haskell-language-server exe candidates: ["haskell-language-server-8.10.4","haskell-language-server-8.10","haskell-language-server"]
Launching haskell-language-server exe at:/home/foo/.ghcup/bin/haskell-language-server-8.10.4
haskell-language-server version: 1.1.0.0 (GHC: 8.10.4) (PATH: /home/foo/.ghcup/bin/haskell-language-server-8.10.4~1.1.0) (GIT hash: f1c096927186a93d8e3ccd4fe8385cc1b070350b)
 ghcide setup tester in /home/foo/projects/example.
Report bugs at https://github.com/haskell/haskell-language-server/issues

Step 1/4: Finding files to test in /home/foo/projects/example
Found 3 files

Step 2/4: Looking for hie.yaml files that control setup
Found 1 cradle
  (/home/foo/projects/example/hie.yaml)

Step 3/4: Initializing the IDE

Step 4/4: Type checking the files
2021-06-25 18:44:24.988266282 [ThreadId 4] DEBUG hls:   Set files of interest to: [(NormalizedFilePath "/home/foo/projects/example/pqexample/src/PQ.hs",OnDisk),(NormalizedFilePath "/home/foo/projects/example/src/B.hs",OnDisk),(NormalizedFilePath "/home/foo/projects/example/src/A.hs",OnDisk)]
2021-06-25 18:44:24.989627599 [ThreadId 79] DEBUG hls:  hlint:getIdeas:file:NormalizedFilePath "/home/foo/projects/example/src/B.hs"
2021-06-25 18:44:24.989635104 [ThreadId 78] DEBUG hls:  hlint:getIdeas:file:NormalizedFilePath "/home/foo/projects/example/pqexample/src/PQ.hs"
2021-06-25 18:44:24.989662114 [ThreadId 77] DEBUG hls:  hlint:getIdeas:file:NormalizedFilePath "/home/foo/projects/example/src/A.hs"
2021-06-25 18:44:24.990188754 [ThreadId 93] INFO hls:   Consulting the cradle for "src/B.hs"
Output from setting up the cradle Cradle {cradleRootDir = "/home/foo/projects/example", cradleOptsProg = CradleAction: Stack}
> Configuring GHCi with the following packages: example
> /home/foo/projects/example/.stack-work/install/x86_64-linux-tinfo6/e857431271b4cd29c78b6f2c970b9abcee6d8c8df77a6c0b3dbb05e050835ce0/8.10.4/pkgdb:/home/foo/.stack/snapshots/x86_64-linux-tinfo6/e857431271b4cd29c78b6f2c970b9abcee6d8c8df77a6c0b3dbb05e050835ce0/8.10.4/pkgdb:/home/foo/.stack/programs/x86_64-linux/ghc-tinfo6-8.10.4/lib/ghc-8.10.4/package.conf.d
2021-06-25 18:44:26.009985491 [ThreadId 93] DEBUG hls:  Session loading result: Right (ComponentOptions {componentOptions = ["-i","-odir=/home/foo/projects/example/.stack-work/odir","-hidir=/home/foo/projects/example/.stack-work/odir","-hide-all-packages","-i/home/foo/projects/example/.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.2.1.0/build","-i/home/foo/projects/example/src","-i/home/foo/projects/example/.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.2.1.0/build/autogen","-i/home/foo/projects/example/.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.2.1.0/build/global-autogen","-stubdir=/home/foo/projects/example/.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.2.1.0/build","-package-id=base-4.14.1.0","-package-id=template-haskell-2.16.0.0","-package-id=pqexample-0.0.0-AYIBm2U3Aq37TXbYsGw9pl","-optP-include","-optP/home/foo/projects/example/.stack-work/ghci/78a2b7ee/cabal_macros.h","-ghci-script=/tmp/haskell-stack-ghci/f9e95283/ghci-script","-package-db","/home/foo/projects/example/.stack-work/install/x86_64-linux-tinfo6/e857431271b4cd29c78b6f2c970b9abcee6d8c8df77a6c0b3dbb05e050835ce0/8.10.4/pkgdb","-package-db","/home/foo/.stack/snapshots/x86_64-linux-tinfo6/e857431271b4cd29c78b6f2c970b9abcee6d8c8df77a6c0b3dbb05e050835ce0/8.10.4/pkgdb","-package-db","/home/foo/.stack/programs/x86_64-linux/ghc-tinfo6-8.10.4/lib/ghc-8.10.4/package.conf.d"], componentRoot = "/home/foo/projects/example", componentDependencies = ["example.cabal","package.yaml","stack.yaml"]},"/home/foo/.stack/programs/x86_64-linux/ghc-tinfo6-8.10.4/lib/ghc-8.10.4")
2021-06-25 18:44:26.0532338 [ThreadId 93] INFO hls:     Using interface files cache dir: /home/foo/.cache/ghcide/main-a70ef1e6d9d19e2d3c084465e0fae5c1e4416e60
2021-06-25 18:44:26.053352853 [ThreadId 93] INFO hls:   Making new HscEnv[main]
2021-06-25 18:44:26.057649144 [ThreadId 93] DEBUG hls:  New Component Cache HscEnvEq: (([],Just HscEnvEq 5),fromList [("/home/foo/projects/example/hie.yaml",Just 2021-06-25 22:41:56.808948705 UTC),("example.cabal",Just 2021-06-25 22:30:37.774550911 UTC),("package.yaml",Nothing),("stack.yaml",Just 2021-06-25 22:30:57.242622243 UTC)])
2021-06-25 18:44:26.060152966 [ThreadId 93] DEBUG hls:  Known files updated: fromList [(TargetModule A,fromList ["/home/foo/projects/example/src/A.hs"]),(TargetModule B,fromList ["/home/foo/projects/example/src/B.hs"]),(TargetFile NormalizedFilePath "/home/foo/projects/example/src/B.hs",fromList ["/home/foo/projects/example/src/B.hs"])]
2021-06-25 18:44:26.060493996 [ThreadId 34] DEBUG hls:  Finishing build session(exception: AsyncCancelled)
2021-06-25 18:44:26.06059176 [ThreadId 93] DEBUG hls:   Restarting build session (aborting the previous one took 0.00s)
2021-06-25 18:44:26.061951083 [ThreadId 178] DEBUG hls: hlint:getIdeas:file:NormalizedFilePath "/home/foo/projects/example/src/B.hs"
2021-06-25 18:44:26.061986299 [ThreadId 182] DEBUG hls: hlint:getIdeas:file:NormalizedFilePath "/home/foo/projects/example/src/A.hs"
2021-06-25 18:44:26.061957265 [ThreadId 179] DEBUG hls: hlint:getIdeas:file:NormalizedFilePath "/home/foo/projects/example/pqexample/src/PQ.hs"
2021-06-25 18:44:26.063105552 [ThreadId 198] INFO hls:  Consulting the cradle for "pqexample/src/PQ.hs"
Output from setting up the cradle Cradle {cradleRootDir = "/home/foo/projects/example", cradleOptsProg = CradleAction: Stack}
> Configuring GHCi with the following packages: pqexample
> /home/foo/projects/example/.stack-work/install/x86_64-linux-tinfo6/e857431271b4cd29c78b6f2c970b9abcee6d8c8df77a6c0b3dbb05e050835ce0/8.10.4/pkgdb:/home/foo/.stack/snapshots/x86_64-linux-tinfo6/e857431271b4cd29c78b6f2c970b9abcee6d8c8df77a6c0b3dbb05e050835ce0/8.10.4/pkgdb:/home/foo/.stack/programs/x86_64-linux/ghc-tinfo6-8.10.4/lib/ghc-8.10.4/package.conf.d
2021-06-25 18:44:27.106834505 [ThreadId 198] DEBUG hls: Session loading result: Right (ComponentOptions {componentOptions = ["-i","-odir=/home/foo/projects/example/.stack-work/odir","-hidir=/home/foo/projects/example/.stack-work/odir","-hide-all-packages","-i/home/foo/projects/example/pqexample/.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.2.1.0/build","-i/home/foo/projects/example/pqexample/src","-i/home/foo/projects/example/pqexample/.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.2.1.0/build/autogen","-i/home/foo/projects/example/pqexample/.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.2.1.0/build/global-autogen","-stubdir=/home/foo/projects/example/pqexample/.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.2.1.0/build","-lpq","-package-id=base-4.14.1.0","-optP-include","-optP/home/foo/projects/example/.stack-work/ghci/78665a2f/cabal_macros.h","-ghci-script=/tmp/haskell-stack-ghci/6f47add2/ghci-script","-package-db","/home/foo/projects/example/.stack-work/install/x86_64-linux-tinfo6/e857431271b4cd29c78b6f2c970b9abcee6d8c8df77a6c0b3dbb05e050835ce0/8.10.4/pkgdb","-package-db","/home/foo/.stack/snapshots/x86_64-linux-tinfo6/e857431271b4cd29c78b6f2c970b9abcee6d8c8df77a6c0b3dbb05e050835ce0/8.10.4/pkgdb","-package-db","/home/foo/.stack/programs/x86_64-linux/ghc-tinfo6-8.10.4/lib/ghc-8.10.4/package.conf.d"], componentRoot = "/home/foo/projects/example/pqexample", componentDependencies = ["pqexample/pqexample.cabal","pqexample/package.yaml","stack.yaml"]},"/home/foo/.stack/programs/x86_64-linux/ghc-tinfo6-8.10.4/lib/ghc-8.10.4")
2021-06-25 18:44:27.148598826 [ThreadId 198] INFO hls:  Using interface files cache dir: /home/foo/.cache/ghcide/main-d720665dfd93b30fab40a64d4b09404d904bc716
2021-06-25 18:44:27.148714323 [ThreadId 198] INFO hls:  Using interface files cache dir: /home/foo/.cache/ghcide/main-d720665dfd93b30fab40a64d4b09404d904bc716
2021-06-25 18:44:27.148766752 [ThreadId 198] INFO hls:  Making new HscEnv[main,main]
2021-06-25 18:44:27.152914914 [ThreadId 198] DEBUG hls: New Component Cache HscEnvEq: (([],Just HscEnvEq 7),fromList [("/home/foo/projects/example/hie.yaml",Just 2021-06-25 22:41:56.808948705 UTC),("pqexample/package.yaml",Nothing),("pqexample/pqexample.cabal",Just 2021-06-25 22:32:17.438916399 UTC),("stack.yaml",Just 2021-06-25 22:30:57.242622243 UTC)])
2021-06-25 18:44:27.15370085 [ThreadId 198] DEBUG hls:  New Component Cache HscEnvEq: (([],Just HscEnvEq 8),fromList [("/home/foo/projects/example/hie.yaml",Just 2021-06-25 22:41:56.808948705 UTC),("example.cabal",Just 2021-06-25 22:30:37.774550911 UTC),("package.yaml",Nothing),("stack.yaml",Just 2021-06-25 22:30:57.242622243 UTC)])
2021-06-25 18:44:27.156896523 [ThreadId 198] DEBUG hls: Known files updated: fromList [(TargetModule PQ,fromList ["/home/foo/projects/example/pqexample/src/PQ.hs"]),(TargetModule A,fromList ["/home/foo/projects/example/src/A.hs"]),(TargetFile NormalizedFilePath "/home/foo/projects/example/pqexample/src/PQ.hs",fromList ["/home/foo/projects/example/pqexample/src/PQ.hs"]),(TargetModule B,fromList ["/home/foo/projects/example/src/B.hs"]),(TargetFile NormalizedFilePath "/home/foo/projects/example/src/B.hs",fromList ["/home/foo/projects/example/src/B.hs"])]
2021-06-25 18:44:27.157257301 [ThreadId 122] DEBUG hls: Finishing build session(exception: AsyncCancelled)
2021-06-25 18:44:27.157369682 [ThreadId 198] DEBUG hls: Restarting build session (aborting the previous one took 0.00s)
2021-06-25 18:44:27.158906439 [ThreadId 342] DEBUG hls: hlint:getIdeas:file:NormalizedFilePath "/home/foo/projects/example/pqexample/src/PQ.hs"
2021-06-25 18:44:27.158877244 [ThreadId 338] DEBUG hls: hlint:getIdeas:file:NormalizedFilePath "/home/foo/projects/example/src/A.hs"
2021-06-25 18:44:27.161917314 [ThreadId 444] DEBUG hls: hlint:getIdeas:file:NormalizedFilePath "/home/foo/projects/example/src/B.hs"
haskell-language-server-wrapper: callProcess: /home/foo/.ghcup/bin/haskell-language-server-8.10.4 "--debug" (exit -11): failed

Me and a collegue went down the route to figure out why we were getting segfaults when compiling our project. We drilled down until we could get the smallest reproducible project. The issue ends up being that if you import a project that loads pq (or libpq) regardless of its contents you get a segfault with no information as to why. If your own project imports pq it does not segfault. If you depend on a project that imports pq but don't import that project then it won't segfault. It was very interesting to reach this conclusion. You can play around with the example project to see what segfaults and what doesn't. I would be interested to see if different OS's react differently though. Also it's possible that my libpq is at fault as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugSomething isn't right: doesn't work as intended, documentation is missing/outdated, etc..

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions