Simple "Hello World" Warp-based web server crashes on Ubuntu x86_64

Hello dear GHC developers, I have recently experienced what I believe to be a bug either in GHC or in Warp library (if it is indeed in Warp then sorry for posting to wrong mailing list). I've managed to shrink it to a few lines of code and publish on a GitHub. Here is the link: https://github.com/anton-dessiatov/warp-ghc-issue What I wanted to do is to establish network connection in my code and then at some point pass it to Warp for further processing. What I got is that after successfully processing first HTTP request my program consumes 100% CPU and eventually crashes with an error like this: *** Error in `/home/farnsworth/work/warp-ghc-issue/.stack-work/install/x86_64-linux/lts-5.5/7.10.3/bin/warp-ghc-issue': double free or corruption (!prev): 0x00000000016214b0 *** Aborted (core dumped) When compiled with -debug I see another message: repro: internal error: ASSERTION FAILED: file rts/Schedule.h, line 137 (GHC version 7.10.3 for x86_64_unknown_linux) Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug Aborted (core dumped) I tried to debug it by enabling -dcore-lint and -debug in my ~/.stack/config.yaml and what worries me is that in this case Warp itself doesn't compile (tried with 7.10.2 and 7.10.3) giving core lint failure in Network.Wai.Handler.Warp.HTTP2.Worker. Not sure if it is relevant, but looks suspicious. Could anybody please try building my code on x64 Linux, run it, open localhost:8080 in a web browser and confirm that there is indeed a bug? Regards, Anton.

Антон Десятов
Hello dear GHC developers,
I have recently experienced what I believe to be a bug either in GHC or in Warp library (if it is indeed in Warp then sorry for posting to wrong mailing list). I've managed to shrink it to a few lines of code and publish on a GitHub. Here is the link: https://github.com/anton-dessiatov/warp-ghc-issue
What I wanted to do is to establish network connection in my code and then at some point pass it to Warp for further processing. What I got is that after successfully processing first HTTP request my program consumes 100% CPU and eventually crashes with an error like this:
*** Error in `/home/farnsworth/work/warp-ghc-issue/.stack-work/install/x86_64-linux/lts-5.5/7.10.3/bin/warp-ghc-issue': double free or corruption (!prev): 0x00000000016214b0 *** Aborted (core dumped)
When compiled with -debug I see another message:
repro: internal error: ASSERTION FAILED: file rts/Schedule.h, line 137
(GHC version 7.10.3 for x86_64_unknown_linux) Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug Aborted (core dumped)
I tried to debug it by enabling -dcore-lint and -debug in my ~/.stack/config.yaml and what worries me is that in this case Warp itself doesn't compile (tried with 7.10.2 and 7.10.3) giving core lint failure in Network.Wai.Handler.Warp.HTTP2.Worker. Not sure if it is relevant, but looks suspicious.
This indeed quite relevant and concerning. Core lint issues should not occur; they mean that somehow GHC has taken correct code (it typechecked, afterall) and turned it into something horrible. That being said, I'm afraid I can't reproduce this issue locally. What warp version are you building against? In the meantime, could you open a bug on the GHC Trac for this issue? It would be quite helpful if you could attach the output from Core Lint when you do so. Cheers, - Ben

Hello Ben, I am bulding warp-3.2.2 with stack (lts-5.5 snapshot) using GHC 7.10.3. I have also created a ticket in GHC trac: https://ghc.haskell.org/trac/ghc/ticket/11664. Hope this helps. Regards, Anton. 01.03.2016 21:53, Ben Gamari пишет:
Антон Десятов
writes: Hello dear GHC developers,
I have recently experienced what I believe to be a bug either in GHC or in Warp library (if it is indeed in Warp then sorry for posting to wrong mailing list). I've managed to shrink it to a few lines of code and publish on a GitHub. Here is the link: https://github.com/anton-dessiatov/warp-ghc-issue
What I wanted to do is to establish network connection in my code and then at some point pass it to Warp for further processing. What I got is that after successfully processing first HTTP request my program consumes 100% CPU and eventually crashes with an error like this:
*** Error in `/home/farnsworth/work/warp-ghc-issue/.stack-work/install/x86_64-linux/lts-5.5/7.10.3/bin/warp-ghc-issue': double free or corruption (!prev): 0x00000000016214b0 *** Aborted (core dumped)
When compiled with -debug I see another message:
repro: internal error: ASSERTION FAILED: file rts/Schedule.h, line 137
(GHC version 7.10.3 for x86_64_unknown_linux) Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug Aborted (core dumped)
I tried to debug it by enabling -dcore-lint and -debug in my ~/.stack/config.yaml and what worries me is that in this case Warp itself doesn't compile (tried with 7.10.2 and 7.10.3) giving core lint failure in Network.Wai.Handler.Warp.HTTP2.Worker. Not sure if it is relevant, but looks suspicious.
This indeed quite relevant and concerning. Core lint issues should not occur; they mean that somehow GHC has taken correct code (it typechecked, afterall) and turned it into something horrible.
That being said, I'm afraid I can't reproduce this issue locally. What warp version are you building against?
In the meantime, could you open a bug on the GHC Trac for this issue? It would be quite helpful if you could attach the output from Core Lint when you do so.
Cheers,
- Ben

Hi,
repro: internal error: ASSERTION FAILED: file rts/Schedule.h, line 137
(GHC version 7.10.3 for x86_64_unknown_linux) Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug Aborted (core dumped)
I can reproduce this on my 64bit Mac. But the code in https://github.com/anton-dessiatov/warp-ghc-issue is very starange to me. Why do you use interal APIs such as socketConnection runSettingsConnection? Why don't you use normal APIs such as runSettingsSocket? I guess your usage of the internal APIs triggers an infinite loop. --Kazu

Hello Kazu, My original intent was to accept different kinds of traffic on the same port. Then I wanted to figure out what protocol is used by analyzing first few received bytes and if that's HTTP, pass it to Warp. So I used internal runSettingsConnection to continue processing after connection has already been established. Current "warp-ghc-issue" repository doesn't have all the protocol detection machinery and all that it does is simply accepting socket and passing it to runSettingsConnection. At the first glance it seems fully legitimate, but triggers behavior described. I have studied Warp source code to figure out what could possibly go wrong, but currently it just looks to me that I do almost exactly the same things as public Network.Wai.Handler.Warp.run function (except for async exceptions handling, supporting TLS and other features). I don't see how could I trigger an infinite loop (although I admit that something goes very wrong with my code and doesn't go wrong with Warp's run function). Even if that's an infinite loop - why does it crash instead of just looping? Do you think I should create an issue at Warp's bug tracker? Regards, Anton. 02.03.2016 6:59, Kazu Yamamoto (山本和彦) пишет:
Hi,
repro: internal error: ASSERTION FAILED: file rts/Schedule.h, line 137
(GHC version 7.10.3 for x86_64_unknown_linux) Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug Aborted (core dumped) I can reproduce this on my 64bit Mac.
But the code in https://github.com/anton-dessiatov/warp-ghc-issue is very starange to me. Why do you use interal APIs such as socketConnection runSettingsConnection? Why don't you use normal APIs such as runSettingsSocket?
I guess your usage of the internal APIs triggers an infinite loop.
--Kazu

Ouch! Looks like I nailed down this one. Indeed that's my bad and that's an infinite loop I have unwillingly created in Network.Wai.Handler.Warp.Run.acceptConnection. Sorry for suspecting GHC failure where there is my fault. At the very least I have an excuse that this mistake of mine helped to identify at least one actual bug in GHC master. 02.03.2016 14:19, Anton Dessiatov пишет:
Hello Kazu,
My original intent was to accept different kinds of traffic on the same port. Then I wanted to figure out what protocol is used by analyzing first few received bytes and if that's HTTP, pass it to Warp. So I used internal runSettingsConnection to continue processing after connection has already been established.
Current "warp-ghc-issue" repository doesn't have all the protocol detection machinery and all that it does is simply accepting socket and passing it to runSettingsConnection. At the first glance it seems fully legitimate, but triggers behavior described.
I have studied Warp source code to figure out what could possibly go wrong, but currently it just looks to me that I do almost exactly the same things as public Network.Wai.Handler.Warp.run function (except for async exceptions handling, supporting TLS and other features). I don't see how could I trigger an infinite loop (although I admit that something goes very wrong with my code and doesn't go wrong with Warp's run function).
Even if that's an infinite loop - why does it crash instead of just looping? Do you think I should create an issue at Warp's bug tracker?
Regards, Anton.
02.03.2016 6:59, Kazu Yamamoto (山本和彦) пишет:
Hi,
repro: internal error: ASSERTION FAILED: file rts/Schedule.h, line 137
(GHC version 7.10.3 for x86_64_unknown_linux) Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug Aborted (core dumped) I can reproduce this on my 64bit Mac.
But the code in https://github.com/anton-dessiatov/warp-ghc-issue is very starange to me. Why do you use interal APIs such as socketConnection runSettingsConnection? Why don't you use normal APIs such as runSettingsSocket?
I guess your usage of the internal APIs triggers an infinite loop.
--Kazu

Anton Dessiatov
Ouch! Looks like I nailed down this one. Indeed that's my bad and that's an infinite loop I have unwillingly created in Network.Wai.Handler.Warp.Run.acceptConnection.
Well, that being said, the various Core Lint issues that you found are quite concerning. It would be greatly appreciated if you could follow up with those (in particular the unresolved attoparsec issue).
Sorry for suspecting GHC failure where there is my fault.
Quite alright; GHC certainly isn't infallible. Cheers, - Ben

Simon Peyton Jones have recently commented on #11665 (attoparsec one) and it looks like he has it well under control. Of course I would be glad to try reproducing that again if needed. Talking about #11664 I think it's worth knowing that GHC 7.10.3 has some hard time compiling recent Warp, but the good point is that (supposedly) GHC 8.0 doesn't have this problem anymore, so the ticket could be relatively safely closed. 02.03.2016 20:50, Ben Gamari пишет:
Anton Dessiatov
writes: Ouch! Looks like I nailed down this one. Indeed that's my bad and that's an infinite loop I have unwillingly created in Network.Wai.Handler.Warp.Run.acceptConnection.
Well, that being said, the various Core Lint issues that you found are quite concerning. It would be greatly appreciated if you could follow up with those (in particular the unresolved attoparsec issue).
Sorry for suspecting GHC failure where there is my fault.
Quite alright; GHC certainly isn't infallible.
Cheers,
- Ben
participants (4)
-
Anton Dessiatov
-
Ben Gamari
-
Kazu Yamamoto
-
Антон Десятов