commercialhaskell / stack

The Haskell Tool Stack
http://haskellstack.org
BSD 3-Clause "New" or "Revised" License
3.96k stars 844 forks source link

Connection Failure error with hackage.haskell.org #5994

Open Mechap opened 1 year ago

Mechap commented 1 year ago

I am on arch linux and I installed stack through ghcup. However, running stack always resutlts in a connection failure.

Steps to reproduce

Run command stack update

Expected

It should run without errors.

Actual

stack update --verbose
Version 2.9.1, Git revision 409d56031b4240221d656db09b2ba476fe6bb5b1 x86_64 hpack-0.35.0
2022-12-28 10:20:54.442871: [debug] Checking for project config at: /home/mechap/stack.yaml
2022-12-28 10:20:54.443596: [debug] Checking for project config at: /home/stack.yaml
2022-12-28 10:20:54.443634: [debug] Checking for project config at: /stack.yaml
2022-12-28 10:20:54.443661: [debug] No project config file found, using defaults.
2022-12-28 10:20:54.454144: [debug] (SQL) SELECT COUNT(*) FROM "last_performed" WHERE ("action"=?) AND ("timestamp">=?); [PersistInt64 1,PersistUTCTime 2022-12-27 09:20:54.453673226 UTC]
2022-12-28 10:20:54.456163: [info] Selected mirror https://hackage.haskell.org/
2022-12-28 10:20:54.456258: [info] Downloading root
2022-12-28 10:20:59.463542: [error] HttpExceptionRequest Request {
  host                 = "hackage.haskell.org"
  port                 = 443
  secure               = True
  requestHeaders       = [("Accept-Encoding",""),("User-Agent","Haskell pantry package")]
  path                 = "/root.json"
  queryString          = ""
  method               = "GET"
  proxy                = Nothing
  rawBody              = False
  redirectCount        = 10
  responseTimeout      = ResponseTimeoutDefault
  requestVersion       = HTTP/1.1
  proxySecureMode      = ProxySecureWithConnect
}
 (ConnectionFailure Network.Socket.getAddrInfo (called with preferred socket type/protocol: AddrInfo {addrFlags = [AI_ADDRCONFIG], addrFamily = AF_UNSPEC, addrSocketType = Stream, addrProtocol = 0, addrAddress = 0.0.0.0:0, addrCanonName = Nothing}, host name: Just "hackage.haskell.org", service name: Just "443"): does not exist (Try again))
curl -I https://hackage.haskell.org:443/root.json
HTTP/1.1 200 OK
Connection: keep-alive
Content-Length: 4216
Server: nginx/1.18.0 (Ubuntu)
Content-Type: application/json
Cache-Control: public, no-transform, max-age=60
Content-MD5: MKHLRXfk9A1kOc9X0OA7Jg==
ETag: "30a1cb4577e4f40d6439cf57d0e03b26"
Accept-Ranges: bytes
Date: Wed, 28 Dec 2022 09:24:43 GMT
Via: 1.1 varnish
Age: 0
X-Served-By: cache-cdg20728-CDG
X-Cache: HIT
X-Cache-Hits: 1
X-Timer: S1672219483.965029,VS0,VE459
Vary: Accept-Encoding

Stack version

stack --version
Version 2.9.1, Git revision 409d56031b4240221d656db09b2ba476fe6bb5b1 x86_64 hpack-0.35.0
mpilgrem commented 1 year ago

@Mechap, thanks for reporting. That is odd. I see that Stack thinks that the URL does not exist but curl can return the HTTP-header. I do not have experience with networks, but could it be a firewall problem?

Mechap commented 1 year ago

It could also be related to my proxy config. I think it uses 0.0.0.0:0 because I didn't set proxy environment variables.

mpilgrem commented 1 year ago

@Mechap, all I can suggest for the moment is (a) to search the issues here for key words. People do have network issues from time to time and the advice they received may help you; and/or (b) post on the Haskell Community. It will likely reach a wider audience than here.

chris-martin commented 1 year ago

Maybe a duplicate of #5921

I have the same problem, on NixOS. Stack has been unusable for me for a month or so now.

$ stack build
Exception while reading snapshot from https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/17/11.yaml:
HttpExceptionRequest Request {
  host                 = "raw.githubusercontent.com"
  port                 = 443
  secure               = True
  requestHeaders       = [("User-Agent","Haskell pantry package")]
  path                 = "/commercialhaskell/stackage-snapshots/master/lts/17/11.yaml"
  queryString          = ""
  method               = "GET"
  proxy                = Nothing
  rawBody              = False
  redirectCount        = 10
  responseTimeout      = ResponseTimeoutDefault
  requestVersion       = HTTP/1.1
  proxySecureMode      = ProxySecureWithConnect
}
 ConnectionTimeout

Fails like this every time.

curl can fetch the address https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/17/11.yaml just fine.

I just installed the latest from nixpkgs.

$ nix profile install 'nixpkgs/nixos-unstable#stack'
$ stack --version
2.9.1 x86_64 hpack-0.35.1

Can also consistently reproduce the issue with:

... and I stopped trying at that point.

chris-martin commented 1 year ago

I can't even begin to speculate why, but I fixed the problem by disabling ipv6 on my router.

ejconlon commented 1 year ago

FWIW I encountered this error on a Linux machine on my home network (behind NAT). Once I disabled ipv6 altogether through systemctl, things proceeded normally.

why-not-try-calmer commented 8 months ago

I can't even begin to speculate why, but I fixed the problem by disabling ipv6 on my router.

Just ran into the same issue and the same solution worked for me. I am torn between relief and disgust.

Vlix commented 8 months ago

Does anyone know if Network.Socket.getAddrInfo works with IPv6? Like, if looking for a host name returns ONLY an IPv6 and no IPv4? 🤔

turion commented 1 month ago

I have a similar error on NixOS:

❯ stack init --resolver nightly -v
2.15.5 x86_64 hpack-0.36.0
2024-06-13 11:37:34.585105: [debug] No project config file found, using defaults.
2024-06-13 11:37:34.592873: [debug] Use of Casa server enabled: (CasaRepoPrefix "https://casa.stackage.org", 1280).
2024-06-13 11:37:34.594989: [debug] (SQL) SELECT COUNT(*) FROM "last_performed" WHERE ("action"=?) AND ("timestamp">=?); [PersistInt64 1,PersistUTCTime 2024-06-12 09:37:34.594962767 UTC]
2024-06-13 11:37:34.595915: [debug] Using resolver: nightly specified on command line
2024-06-13 11:37:34.596001: [debug] Downloading snapshot versions file from https://stackage-haddock.haskell.org/snapshots.json
2024-06-13 11:38:04.629361: [error] HttpExceptionRequest Request {
  host                 = "stackage-haddock.haskell.org"
  port                 = 443
  secure               = True
  requestHeaders       = [("Accept","application/json"),("User-Agent","The Haskell Stack")]
  path                 = "/snapshots.json"
  queryString          = ""
  method               = "GET"
  proxy                = Nothing
  rawBody              = False
  redirectCount        = 10
  responseTimeout      = ResponseTimeoutDefault
  requestVersion       = HTTP/1.1
  proxySecureMode      = ProxySecureWithConnect
}
 ConnectionTimeout

IPv6 sounds like a likely culprit.

turion commented 1 month ago

On NixOS, a workaround is setting this in your config:

networking.enableIPv6 = false;

(Of course that's quite a sledgehammer and you'd typically want to revert this setting soon.)