Closed rszibele closed 6 years ago
Just to be sure, can you try the following after issuing the command stack exec --yesod devel
:
ExitSuccess
Enter
in console. That will issue a rebuild. Wait till it get's completed and check again in the browser.Let me know if that helps/doesn't help.
Thanks for the quick response, psibi. Following your instructions, ExitSuccess
no longer appears after a rebuild by pressing Enter
in the console so I assume it should be running now. However, it still displays The application isn't built
.
What I've also tried in the meanwhile:
stack upgrade
I unfortunately still get the same issue.
I tried and did exactly the same thing in a virtual machine on Ubuntu 18.04 and it works. I'll be investigating why it doesn't work on OpenSUSE Leap 15.
Ok, this is strange. It only listens on ipv6 even though in the configuration (settings.yml) it should listen on any ipv4 address: _env:HOST:*4
.
richard@linux-aovt:~> ss -ltn
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 5 127.0.0.1:631 0.0.0.0:*
LISTEN 0 100 127.0.0.1:25 0.0.0.0:*
LISTEN 0 50 *:1716 *:*
LISTEN 0 5 [::1]:631 [::]:*
LISTEN 0 128 [2003:ec:ebde:500:307a:66cb:af80:d056]:3000 [::]:*
LISTEN 0 100 [::1]:25 [::]:*
Opening [2003:ec:ebde:500:307a:66cb:af80:d056]:3000
in Firefox shows the web page.
That's strange. I checked on my Ubuntu machine too and the template worked fine. Not really sure why this is happening with OpenSUSE.
According to http://hackage.haskell.org/package/warp-3.2.22/docs/Network-Wai-Handler-Warp.html#t:HostPreference *4
means any IPv4 or IPv6 hostname, IPv4 preferred
, so I thought changing it to !4
which means any IPv4 hostname
would solve it, but I still get the same result. I also tried 127.0.0.1
or localhost
without success.
Found the issue, OpenSUSE doesn't bind the hostname to localhost on a fresh install which causes this issue.
I'll have to reopen this as I've spoken with the lads over at freenode #SUSE and they say it's an issue with the framework as it shouldn't be a requirement that the hostname is bound to localhost. What I also find strange is that 127.0.0.1
, localhost
or !4
didn't work, it should, shouldn't it?
What I also find strange is that 127.0.0.1, localhost or !4 didn't work, it should, shouldn't it?
!4
should have worked.
127.0.0.1
should have worked. But it seems to have assigned IPv6 to you. So that explains why that didn't work.
localhost
- Now if it's not binded, it won't work.
BTW, Thanks for the great debugging!
localhost
is bound to 127.0.0.1
, but my computers hostname opensuse
isn't bound to anything in /etc/hosts
, sorry for not being clear. On Ubuntu the computers hostname is bound to a local address, but not on OpenSUSE.
@rszibele So, I looked on to this but I wasn't able to find anything interesting on a Ubuntu based Linux machine. Can you run this program in your SUSE machine:
#!/usr/bin/env stack
{- stack
--resolver lts-11.6
--install-ghc
runghc
--package warp
--package wai
--package http-types
-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
import Network.HTTP.Types
import Network.Wai
import Network.Wai.Handler.Warp
app :: Application
app _req sendResponse =
sendResponse $
responseLBS status200 [("Content-Type", "text/plain")] "Hello Warp!"
main :: IO ()
main = runSettings (setHost "!4" defaultSettings) app
For executing it, you should do stack filename.hs
and check if localhost:3000
works in your browser. And after that can you show the paste the output of the following command here:
$ netstat -lntp
There was one odd behavior which I found using !6
which made it work in both ipv4 and ipv6. But after reading some documentation, that seems to be the case of IPv4-mapped IPv6 addresses. It would be good to document that behavior as part of HostPreferences
IMO.
One minor FYI: if you're using yesod devel
, you'll want to use the --host
parameter on the command line to control which host yesod devel
itself binds to. The config file will affect the application running behind yesod devel
.
@psibi Here's the output of netstat after executing your snippet. It's bound correctly and it works.
richard@opensuse:~/Documents> netstat -lntp
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:3000 0.0.0.0:* LISTEN 30801/ghc
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN -
tcp6 0 0 :::1716 :::* LISTEN 3018/kdeconnectd
tcp6 0 0 ::1:631 :::* LISTEN -
tcp6 0 0 ::1:25 :::* LISTEN -
I've been debugging further and I've been wondering why your snippet works (as in, binds to IPv4) but the getting started project doesn't. It turns out that you pass !4
directly to WAI, while the yesod project detects the presence of the HOST
environment variable and uses that instead if it is defined. OpenSUSE sets this variable by default.
richard@opensuse:~> echo $HOST
opensuse
If I change _env:HOST:*4
to *4
in settings.yml
, the generated project works correctly as it no longer uses the HOST
environment variable.
@snoyberg Now knowing that host gets set to opensuse
on my computer and the setting gets overridden by default, I've also tried running stack exec -- yesod devel --host opensuse
, and it works when I visit http://opensuse:3000
but it prints a bogus message:
Devel application launched: http://localhost:3000
It should actually be http://opensuse:3000
on my computer. The offending line: https://github.com/yesodweb/yesod/blob/master/yesod/Yesod/Default/Config2.hs#L97
To summarize what we've found:
HOST
environment variable by default to the computers hostname and wont work out-of-the-box with yesod because the hostname isn't bound to localhostyesod devel
itself works but doesn't "detect" the app unless the host is provided to yesod devel
as a command line argumentTwo possible solutions which would independently make the getting started projects work out-of-the box:
YESOD_
to prevent clashing of environment variables. For example: _env:YESOD_HOST:*4
and _env:YESOD_PORT:3000
.yesod devel
autodetect and use the same host as the app.I'll be honest: I'm not too terribly thrilled about making changes to Yesod for this case. Having localhost
not working is pretty extreme. I'd be more willing to have a link on the quickstart page saying "You're on OpenSUSE? Click here." That said, I'm OK with prefixing YESOD_
in the template I think. I'm not at all convinced that yesod devel
should do the same thing though; perhaps using IP address instead of localhost
in the display would be OK.
localhost itself works, it's just that yesod binds to the hostname by default and not localhost, which isn't the same thing on OpenSUSE.
The prefix would also fix it, so either of the solutions is a good fix.
I've updated the QuickStart guide for openSUSE users in this PR, as this was the easiest change that both @snoyberg and @rszibele agreed would be acceptable.
IF that PR is merged, I think we can close this issue.
The new templates have been pushed, can you give it a shot again and confirm that the problem has been solved?
@snoyberg Yes, the problem has been resolved.
it's just that yesod binds to the hostname by default and not localhost
confirming that, the HOST
environment variable of yesod
process is actually a default hostname instead of localhost. Which leads to question: why do we prefer it to the localhost
or 127.0.0.1
, like others do?
Following the quick start guide at https://www.yesodweb.com/page/quickstart I can't seem to get yesod-sqlite to work. Everything builds fine but it seems that the executable exits early, thereby only displaying the page with "The application isn't built".
e.g:
What makes me suspicious is the
ExitSuccess
line.My setup: