2016-09-11 32 views
6

Tôi nhận được một phân đoạn GHCI khi cố tạo kết nối cơ sở dữ liệu trong GHCI với postgresql-simple.GHCI Segfault Khi tạo một kết nối cơ sở dữ liệu với postgresql-đơn giản

Tôi đang sử dụng GHC 8.0.1, OSX 10.11.16. Tôi không có một hệ thống GHC, chỉ có một GHC được cài đặt.

Nếu tôi làm như sau trong dự án của tôi, nó segfaults:

$ 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 

tôi nghĩ nó có thể là giá trị xem xét tập tin mà nó đề cập đến, vì vậy đây là những nội dung:

> 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 

Đó là một danh sách tất cả các mô-đun được tải từ dự án (mà biên dịch và chạy tốt).


Dưới đây là kết quả hoàn toàn của tất cả mọi thứ từ bắt đầu ghci lên đến lỗi seg:

$ 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 

biết thêm thông tin

PostgreSQL Version: 9.5, đã cài đặt bằng cách sử dụng EnterpriseDB installer

Yêu cầu để đăng stack.yaml (dưới đây) nhắc tôi về sự cố tôi gặp phải khi trying to install postgresql-libpq. Điều này có lẽ liên quan.

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 (e.g., 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 (e.g., 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] 

Cũng segfaults trên GHC 7.10.3 với resolver LTS-6,17

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

Một ý tưởng của tôi đã

Tôi nghĩ rằng phiên bản của postgresql-libpq Tôi sử dụng được xây dựng với libiconv.2.dylib biên soạn cho PostgreSQL 9.4, nhưng cơ sở dữ liệu tôi đang cố gắng để kết nối với thực là PostgreSQL 9,5. Đây có thể là lý do cho vấn đề của tôi.

A Thing Tôi đã lấy cảm hứng từ đó Idea

Dưới đây là một số bước tôi đã cố gắng để gỡ lỗi thêm và/hoặc sửa lỗi này. Lần đầu tiên tôi liên kết các tệp Postgresql 9.5 *dylib vào thư mục /usr/local/lib của mình để thay thế các tệp cũ được liên kết với phiên bản 9.4 của Postgresql.

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

Sau đó, tôi đã cố gắng để buộc stack để xây dựng lại postgresql-libpqpostgresql-simple theo cách này:

$ 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 

Tại thời điểm đó, nó hứa với tôi nó sẽ xây dựng và cấu hình các gói bị loại bỏ. Tuy nhiên segfaulted khi tôi chạy ở trên, tuy nhiên.

+0

Ảnh chụp nhanh chính xác hàng đêm bạn đang sử dụng (trên thực tế bạn có thể đăng một 'stack.yaml' tối thiểu ở đâu mà điều này vẫn xảy ra?). Điều này cũng xảy ra trên ảnh chụp LTS hiện tại cho bạn không? Bạn đã cài đặt phiên bản postgres nào? Bạn đã tự biên dịch postgres hay cài đặt nó theo cách khác? – user2847643

+0

Cảm ơn nhận xét. Tôi nhớ dựa trên câu hỏi của bạn, rằng tôi đã có vấn đề cài đặt 'postgresql-libpq', có khả năng liên quan đến vấn đề tôi đang gặp phải. Tuy nhiên, nó có vẻ kỳ lạ mà dự án của tôi sẽ biên dịch và chạy tốt, nhưng tôi sẽ nhận được segfaults trong GHCI. Tôi sẽ cố gắng chuyển đổi độ phân giải và xem điều gì xảy ra. Tôi đang sử dụng 'DuplicateRecordFields', nhưng tôi có lẽ có thể bỏ qua nó và cho nó một shot. – erewok

+0

@ user2847643 Tôi cũng đã thử nó với 'lts-6.17' và nó cũng bị phân đoạn ở đó. – erewok

Trả lời

0

Trong khi cố gắng để tạo ra một stack trace cho vấn đề của tôi, tôi phát hiện ra rằng tôi có thể bắt đầu ghci theo cách sau:

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

Và sau đó, đối với bất cứ điều gì, lý do, segfault không xuất hiện và mọi thứ suôn sẻ như mong đợi. Tôi không biết liệu có ai khác thấy điều này hữu ích không.

Điều có vẻ lạ đối với tôi là tôi không gặp sự cố khi mã được biên dịch và chạy. Tôi chỉ gặp vấn đề trong GHCI.

Dù sao, cho đến khi tôi tìm hiểu thêm hoặc ai đó có đề xuất tốt hơn, tôi sẽ đi với điều này để tôi có thể tiếp tục thử nghiệm những gì tôi muốn trong REPL.

+0

Bạn có thể muốn gửi báo cáo lỗi và gửi tin nhắn tới haskell-cafe. Những người sẽ nhận được thêm một vài con mắt về vấn đề của bạn. – dfeuer

Các vấn đề liên quan