GHCI Segfault when creating a database connection using postgresql-simple

I get segfault GHCI when I try to create a database connection in GHCI with postgresql-simple.

I am using GHC 8.0.1, OSX 10.11.16. I do not have a system GHC, only the one that has the stack installed.

If the following is done in my project:

$ stack ghci Loaded GHCi configuration from /private/var/folders/wb/vvtxjd7n2qz02f571yjyr9j40000gs/T/ghci62972/ghci-script gchi> :set -XOverloadedStrings gchi> import Database.PostgreSQL.Simple gchi> let connstr = "host=localhost port=5432 user=myusername password=mypass dbname=local" gchi> conn <- connectPostgreSQL connstr zsh: segmentation fault stack ghci 

I thought it was worth looking at this file that he mentions, so here is the content:

 > cat /private/var/folders/wb/vvtxjd7n2qz02f571yjyr9j40000gs/T/ghci62972/ghci-script :load "/Users/erewok/projects/haskell/simpleservantblog/app/Main.hs" "Api" "Api.Post" "Api.User" "Config" "Html.Home" "Models.Author" "Models.Post" :module + Api Api.Post Api.User Config Html.Home Models.Author Models.Post 

This is a list of all the modules loaded from the project (which compiles and works fine).


Here's the complete output of everything from ghci to seg fault:

 $ stack ghci The following GHC options are incompatible with GHCi and have not been passed to it: -threaded Using main module: 1. Package `simpleservantblog' component exe:simpleservantblog-exe with main-is file: /Users/erewok/projects/haskell/simpleservantblog/app/Main.hs Configuring GHCi with the following packages: simpleservantblog GHCi, version 8.0.1: http://www.haskell.org/ghc/ :? for help Loaded GHCi configuration from /Users/erewok/.ghci [1 of 8] Compiling Models.Author ( /Users/erewok/projects/haskell/simpleservantblog/src/Models/Author.hs, interpreted ) [2 of 8] Compiling Models.Post ( /Users/erewok/projects/haskell/simpleservantblog/src/Models/Post.hs, interpreted ) [3 of 8] Compiling Html.Home ( /Users/erewok/projects/haskell/simpleservantblog/src/Html/Home.hs, interpreted ) [4 of 8] Compiling Api.User ( /Users/erewok/projects/haskell/simpleservantblog/src/Api/User.hs, interpreted ) [5 of 8] Compiling Api.Post ( /Users/erewok/projects/haskell/simpleservantblog/src/Api/Post.hs, interpreted ) [6 of 8] Compiling Config ( /Users/erewok/projects/haskell/simpleservantblog/src/Config.hs, interpreted ) [7 of 8] Compiling Api ( /Users/erewok/projects/haskell/simpleservantblog/src/Api.hs, interpreted ) [8 of 8] Compiling Main ( /Users/erewok/projects/haskell/simpleservantblog/app/Main.hs, interpreted ) Ok, modules loaded: Api, Config, Api.Post, Api.User, Html.Home, Models.Post, Models.Author, Main. Loaded GHCi configuration from /private/var/folders/wb/vvtxjd7n2qz02f571yjyr9j40000gs/T/ghci64266/ghci-script gchi> :set -XOverloadedStrings gchi> import Database.PostgreSQL.Simple gchi> let connstr = "host=localhost port=5432 user=myusername password=mypass dbname=local" gchi> conn <- connectPostgreSQL connstr zsh: segmentation fault stack ghci 

Additional Information

Postgresql Version: 9.5 installed using the EnterpriseDB installer

The request to publish my stack.yaml (which below) reminded me of the problem I had when trying to install postgresql-libpq . This is probably related.

Stack.yaml

 # This file was automatically generated by stack init # For more information, see: http://docs.haskellstack.org/en/stable/yaml_configuration/ # Specifies the GHC version and set of packages available (eg, lts-3.5, nightly-2015-09-21, ghc-7.10.2) resolver: nightly-2016-08-25 # Local packages, usually specified by relative directory name packages: - '.' - location: git: https://www.github.com/mattjbray/elm-export commit: 8868c1f09597f44c2e18e014cd9fbcf8320c3fea extra-dep: True - location: git: https://www.github.com/mattjbray/servant-elm commit: e13c8def8127ea339e9801d804638854947193e8 extra-dep: True # Packages to be pulled from upstream that are not in the resolver (eg, acme-missiles-0.3) extra-deps: - wai-make-assets-0.1.1 # Override default flag values for local packages and extra-deps flags: {} # Extra package databases containing global packages extra-package-dbs: [] # Control whether we use the GHC we find on the path # system-ghc: true # Extra directories used by stack for building # extra-include-dirs: [/path/to/dir] extra-lib-dirs: [/usr/local/opt/libiconv/lib, /usr/local/lib, /usr/lib] 

Also segfaults on GHC 7.10.3 using resolver lts-6.17

 gchi> conn <- connectPostgreSQL connstr zsh: segmentation fault stack ghci --resolver lts-6.17 

I have an idea

I think the version of postgresql-libpq that I use was built using libiconv.2.dylib compiled for Postgresql 9.4 , but the database I'm trying to connect to is actually Postgresql 9.5 . This may be causing my problem.

The thing that I inspired with this idea

Here are a few steps that I took to try to debug further actions and / or fix it. I first linked the Postgresql 9.5 *dylib in my /usr/local/lib directory to replace the old Postgresql 9.4 version related ones.

 $ cd /usr/local/lib $ sudo ln -s -f /Library/PostgreSQL/9.5/lib/*dylib . 

After that, I tried to get stack rebuild postgresql-libpq and postgresql-simple as follows:

  $ stack exec -- ghc-pkg unregister --force postgresql-simple $ stack exec -- ghc-pkg unregister --force postgresql-libpq $ rm -rf ~/.stack/precompiled/x86_64-osx/ghc-8.0.1/1.24.0.0/postgresql-libpq-0.9.1.1/ $ rm -rf ~/.stack/precompiled/x86_64-osx/ghc-8.0.1/1.24.0.0/postgresql-simple-0.5.2.* $ stack build 

At what point did he promise me that he would create and configure remote packages. However, despite the fact that I ran higher, I still broke off.

+6
source share
1 answer

When I tried to create a stack trace for my problem, I found that I could start ghci as follows:

 $ stack ghci --ghci-options -fexternal-interpreter 

And then, for some reason, segfault does not appear, and everything works as expected. I have no idea if anyone else finds this useful.

What seemed strange to me was that I had no problem when the code was compiled and run. I only have a problem in GHCI.

In any case, until I find out more, or someone has a better suggestion, I will go with this to continue testing what I want in REPL.

0
source

All Articles