Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Linux] [Regression] Error Domain=NSURLErrorDomain Code=-1001 under Linux Swift 5.1 #74

Open
mman opened this issue Sep 30, 2019 · 4 comments

Comments

@mman
Copy link

mman commented Sep 30, 2019

I'm trying to use SwiftyRequest for a simple StatHat client under Linux. The code below worked fine in the past under macOS and Linux but was leaking memory on Linux because of #24 and crashing randomly because of #25.

I decided to give it another go now that both issues seem to have been addressed and my app under linux now fails to do any HTTP requests and is always failing with 1001 (timeout).

The same code works fine under macOS. Swift 5.1 from Xcode 11.

It fails consistently with error 1001 under Linux official docker image for swift 5.1.

    DispatchQueue.global().async {
        let request = RestRequest(method: .post, url: "https://api.stathat.com/ez")
        let stat = ["stat": name, "value": v] as [String : Any]
        let json = JSONWrapper(dictionary: ["ezkey": user, "data": [stat]])
        request.messageBody = try? json.serialize()
        request.response() { data, response, error in
            if let e = error {
                Log.error("ERROR: failed to stathatTrackEZValue stat: '\(stat)', error: \(e)")
            } else if let d = data, let s = String(data: d, encoding: .utf8) {
                Log.debug("stathatTrackEZValue: response: \(s)")
            }
        }
    }

All requests seem to be consistently timing out after 60 seconds, the default request timeout. Invoking curl from the docker image against the same API endpoint works. Here is the trace, it seems to be defaulting to http2

* TCP_NODELAY set
* Connected to api.stathat.com (52.207.158.45) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN, server did not agree to a protocol
* Server certificate:
*  subject: CN=*.stathat.com
*  start date: Dec 15 00:00:00 2018 GMT
*  expire date: Jan 15 12:00:00 2020 GMT
*  subjectAltName: host "api.stathat.com" matched cert's "*.stathat.com"
*  issuer: C=US; O=Amazon; OU=Server CA 1B; CN=Amazon
*  SSL certificate verify ok.
> POST /ez HTTP/1.1
> Host: api.stathat.com
> User-Agent: curl/7.58.0
> Accept: */*
> Content-Length: 59
> Content-Type: application/x-www-form-urlencoded
> 
* upload completely sent off: 59 out of 59 bytes
< HTTP/1.1 200 OK
< Content-Type: application/json
< Date: Mon, 30 Sep 2019 13:32:28 GMT
< Content-Length: 41
< Connection: keep-alive

Any obvious mistakes?

@mman
Copy link
Author

mman commented Sep 30, 2019

Couple more details. I actually fire 13 simultaneous requests at the same time like this and some appear to succeed and others to timeout. No pattern. working fine from Mac OS.

@mman
Copy link
Author

mman commented Sep 30, 2019

Here is a simple executable that demonstrates the problem. Simply build and run and it repeatedly fires multiple concurrent http post requests. Works fine under Linux swift 5.0 and fails with timeouts under Linux swift 5.1, so looks like this is a 5.1 issue. Will report a bug.

https://github.com/mman/swifty-request-failer

@mman
Copy link
Author

mman commented Oct 1, 2019

Just tried the version 3.0 and as it avoids using URLSession, it appears to be working fine under both Swift 5.0 and Swift 5.1 under Linux.

This bug appears to be somewhere down in Swift 5.1 Linux URLSession implementation.

Logged to https://bugs.swift.org/browse/SR-11549.

@mman mman changed the title [Linux] Error Domain=NSURLErrorDomain Code=-1001 for working server [Linux] [Regression] Error Domain=NSURLErrorDomain Code=-1001 under Linux Swift 5.1 Oct 2, 2019
@djones6
Copy link
Contributor

djones6 commented Oct 3, 2019

Agreed - until that Foundation bug is fixed, I'd either stick with Swift 5.0.3, or update to SwiftyRequest v3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants