yesodweb / yesod

A RESTful Haskell web framework built on WAI.
http://www.yesodweb.com/
MIT License
2.64k stars 374 forks source link

Segfaults in yesod devel #1391

Open tim-m89 opened 7 years ago

tim-m89 commented 7 years ago

I don't know what the pattern is. Sometimes I change my code and it goes away / comes back. Other times I'm stuck. Retrying and even deleting the .stack-work don't help. For the sqlite template at least, I can hit segfaults without doing any changes. I'm invoking yesod devel via stack. This on lts-8.13:

[ 1 of 11] Compiling Settings         ( Settings.hs, .stack-work\dist\ca59d0ab\build\Settings.o )
[ 2 of 11] Compiling Settings.StaticFiles ( Settings\StaticFiles.hs, .stack-work\dist\ca59d0ab\build\Settings\StaticFiles.o )
Segmentation fault/access violation in generated code
psibi commented 7 years ago

Which operating system ?

If it's Window, it seems a related ghc bug was fixed recently: https://ghc.haskell.org/trac/ghc/ticket/13108

tim-m89 commented 7 years ago

Yep windows. That ticket is only to add some better diagnostics for segfaults, which would help but not fix it.

psibi commented 7 years ago

Ah, right. I'm guessing this is happening in Windows only as I have been unable to get any related errors on Linux recently. I do remember someone facing the same issue with Haskell platform in Windows:

https://www.reddit.com/r/haskell/comments/5pc1ab/announce_haskell_platform_802/dcsltrp/

ricksanchez commented 7 years ago

This also happens in ghci with DevelMain. Specially when invoking update twice overlapping each other. The result is Segmentation fault/access violation in generated code printed twice. It seems like it is random.

The ghc patch will only help to debug this.

ricksanchez commented 7 years ago

The issue is not fixed in 8.2.1, however it prints this instead:

Access violation in generated code when reading 0000000000000000
Access violation in generated code when reading 0000000000000031

However, it happens less often (just my opinion, I didn't measure). This happens both on a page refresh (with running server) and on compile time. I do not have more clues for this. You can try the yesod-postgres template and compiles many times and it can happen. I am talking about the 64bits version, I can rarely compile Yesod in the 8.0.2. The 32 version of 8.0.2 is much more stable than the 64 counterpart. What extra information can I provide to fix these problems?

dten commented 7 years ago

Chiming in to say I get this too which makes yesod devel unusable

snoyberg commented 7 years ago

It looks like three possible different problems are getting conflated in this bug report:

Unfortunately, none of the reports here really provide enough information to debug this. Some basic information like:

dten commented 7 years ago

I do see there's a message from GHC dying in there. Here's my details.

OS: Windows 10, specifically:

PS C:\haskell> [System.Environment]::OSVersion.Version` 
Major  Minor  Build  Revision
-----  -----  -----  --------
10     0      16299  0

yesod version:

PS C:\haskell> yesod version
yesod-bin version: 1.5.2.2

stack version: (sorry it's a git one, it did die on 1.5.1 too though)

PS C:\haskell> stack --version
Version 1.6.0, Git revision 0e756d486a5a4d6fe03e0d448bb8e706c5834ca1 x86_64 hpack-0.18.1

LTS 8.24, which is GHC 8.0.2

normally i see this

PS C:\haskell> stack exec -- yesod devel
ExitSuccess
Type help for available commands. Press enter to force a rebuild.
Starting devel application
Segmentation fault/access violation in generated code
Starting devel application
Segmentation fault/access violation in generated code
Unexpected: child process exited with ExitFailure 1
Trying again
Starting devel application
Segmentation fault/access violation in generated code
Unexpected: child process exited with ExitFailure 1
Trying again
Downloading lts-8.24 build plan ...Yesod devel server. Enter 'quit' or hit Ctrl-C to quit.
Application can be accessed at:

http://localhost:3000
https://localhost:3443
If you wish to test https capabilities, you should set the following variable:
  export APPROOT=https://localhost:3443

but just now when trying to get this data together i saw

blah blah more compiling with nothing exciting...

[118 of 118] Compiling Application      ( src\Application.hs, .stack-work\dist\ca59d0ab\build\Application.o )
my-yesod-example-0.0.0: copy/register
Installing library in
C:\haskell\.stack-work\install\22a81968\lib\x86_64-windows-ghc-8.0.2\my-yesod-example-0.0.0-13ak8jTcpIVJ8dUI4fyjRI
Registering my-yesod-example-0.0.0...
ExitSuccess
Type help for available commands. Press enter to force a rebuild.
Starting devel application
Segmentation fault/access violation in generated code
Starting devel application
devel.hs: internal error: stg_ap_p_ret
    (GHC version 8.0.2 for x86_64_unknown_mingw32)
    Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
Unexpected: child process exited with ExitFailure 3
Trying again
Starting devel application
Segmentation fault/access violation in generated code
Unexpected: child process exited with ExitFailure 1
Trying again
Starting devel application
Segmentation fault/access violation in generated code
Unexpected: child process exited with ExitFailure 1
Trying again
Yesod devel server. Enter 'quit' or hit Ctrl-C to quit.
Application can be accessed at:

http://localhost:3000
https://localhost:3443
If you wish to test https capabilities, you should set the following variable:
  export APPROOT=https://localhost:3443
snoyberg commented 6 years ago

Based on that output, I don't think there's anything we can do in yesod devel. It looks like a GHC bug. One option would be to try out a nightly snapshot and see if that solves the problem for you (since nightly is using GHC 8.2.1).

paul-rouse commented 6 years ago

@snoyberg I am wondering whether this is related to persistent issue #679, which looks somewhat similar. Although reported under persistent, it is a Yesod build on Windows, and looks as if it may be something to do with GHC.

I have been trying to test the persistent one, but I don't use Windows normally, and I am having trouble getting a build together at the moment. There is a patched GHC to try, referenced in one of the comments in #697.

dten commented 6 years ago

Any thoughts why it would only happen in the yesod devel version of things not the normal stack build?

snoyberg commented 6 years ago

You can try building with the same flags that yesod devel would use: stack build --flag projname:dev --flag projname:library-only --fast

dten commented 6 years ago

i did stack clean, then that, and it did not result in any segfault

snoyberg commented 6 years ago

And to confirm, doing a stack clean and then running yesod devel reliably results in a segfault during build?

Not that I think it should make a difference, but can you try upgrading to the latest yesod-bin (1.5.2.6)

Final note: you can also run with yesod devel --verbose to get more information on what commands are being run by yesod devel.

dten commented 6 years ago

so the command stack exec -- env PORT=44056 DISPLAY_PORT=3000 runghc app/devel.hs is what segfaults

snoyberg commented 6 years ago

Then my recommendation would be to next test a different GHC version and see if the problem still occurs.

dten commented 6 years ago

i got the version with a supposed fix in from the issue referenced earlier. i have that on my path

PS C:\haskell> ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.3.20171021

and i put compiler: ghc-8.3.20171021 in my stack.yaml

but looks like yesod doesn't want to try use it

PS C:\haskell> stack --system-ghc exec -- yesod devel
No information found for ghc-8.3.20171021.
Supported versions for OS key 'windows64': GhcVersion 7.8.4, GhcVersion 7.10.1, GhcVersion 7.10.2, GhcVersion 7.10.3, GhcVersion 8.0.1, GhcVersion 8.0.2, GhcVersion 8.2.1
Type help for available commands. Press enter to force a rebuild.

edit: seems maybe it's stack saying no

snoyberg commented 6 years ago

Can you put system-ghc: true in your stack.yaml? The argument isn't being forwarded from yesod devel.

On Mon, Nov 20, 2017 at 2:02 PM, David Hewson notifications@github.com wrote:

i got the version with a supposed fix in from the issue referenced earlier. i have that on my path

PS C:\haskell> ghc --version The Glorious Glasgow Haskell Compilation System, version 8.3.20171021

and i put compiler: ghc-8.3.20171021 in my stack.yaml

but looks like yesod doesn't want to try use it

PS C:\haskell> stack --system-ghc exec -- yesod devel No information found for ghc-8.3.20171021. Supported versions for OS key 'windows64': GhcVersion 7.8.4, GhcVersion 7.10.1, GhcVersion 7.10.2, GhcVersion 7.10.3, GhcVersion 8.0.1, GhcVersion 8.0.2, GhcVersion 8.2.1 Type help for available commands. Press enter to force a rebuild.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/yesodweb/yesod/issues/1391#issuecomment-345676275, or mute the thread https://github.com/notifications/unsubscribe-auth/AADBB05sBx_SqgyWraytJzyWYoALAfaAks5s4WpRgaJpZM4NUplm .

dten commented 6 years ago

that got further but i get many compile errors

Mistuke commented 6 years ago

Yes unfortunately ghc 8.4 has further changes to base that make it not a drop in replacement for 8.2, I can try to backport the changes to 8.2 for testing this weekend.

tsouanas commented 6 years ago

I'm getting a similar error, following the instructions of yesod's quickstart page, I'm stuck on step 4:

Building all executables for `sigatauga' once. After a successful build of all of them, only specified executables will be rebuilt.   
sigatauga-0.0.0: build (lib + exe)
Preprocessing library for sigatauga-0.0.0..                                                                                           
Building library for sigatauga-0.0.0..
[ 4 of 12] Compiling Settings.StaticFiles ( src/Settings/StaticFiles.hs, .stack-work/dist/x86_64-openbsd/Cabal-2.0.1.0/build/Settings/S
taticFiles.o )

--  While building custom Setup.hs for package sigatauga-0.0.0 using:
      /cave/thanos/.stack/setup-exe-cache/x86_64-openbsd/Cabal-simple_mPHDZzAJ_2.0.1.0_ghc-8.2.2 --builddir=.stack-work/dist/x86_64-ope
nbsd/Cabal-2.0.1.0 build lib:sigatauga exe:sigatauga --ghc-options " -ddump-hi -ddump-to-file -fdiagnostics-color=always"
    Process exited with code: ExitFailure (-10)

Any workarounds, even ugly ones? I'm on OpenBSD (current), I'm using the system's ghc (8.2.2), and stack with lts-10.4. BTW, where can I find out what the -10 stands for?