URLSession works on MacOS fail on Linux

I have one URLSession request that if i make from MacOS it work but if made in Linux (docker) it never have callback even if wait like 10 minutes. It's like entering totally void.

Here you have example that you can run on MacOS and see the print
"Goodbye, world!" and then you can run the same project on docker and see that it does not work.

What can i do?
Thank you

That sounds like a Swift on Linux bug. Would you mind filing a bug at bugs.swift.org ? Also, what Swift version on Linux is this?

So on linux side i did try swift version 5.1 and version 5.2.
Yes I will fill the swift bug....thanks

Could it be that the server is not sending back a "WWW-Authenticate" header field with its 401 error, and that trips up URLSession?

"A server generating a 401 (Unauthorized) response MUST send a WWW-Authenticate header field containing at least one challenge."

I don't see that field when printing out the returned data on the mac.

If you do curl you can see the:
WWW-Authenticate: Bearer realm="Example Service", scope="client.example.api"

Full curl:
* Trying 217.144.77.67...
* TCP_NODELAY set
* Connected to dev01.example.com (217.144.77.67) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: /etc/ssl/cert.pem
CApath: none
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (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, Change cipher spec (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN, server accepted to use http/1.1
* Server certificate:
* subject: CN=dev01.example.com
* start date: Apr 4 12:42:55 2019 GMT
* expire date: Apr 4 21:59:00 2021 GMT
* subjectAltName: host "dev01.example.com" matched cert's "dev01.example.com"
* issuer: C=NO; O=Buypass AS-983163327; CN=Buypass Class 2 CA 2
* SSL certificate verify ok.
> GET /example/dossiers HTTP/1.1
> Host: dev01.example.com
> User-Agent: curl/7.64.1
> Accept: /
>
< HTTP/1.1 401 Unauthorized
< Date: Mon, 27 Apr 2020 17:36:22 GMT
< Server: Apache
< Strict-Transport-Security: max-age=31536000; includeSubDomains
< X-Robots-Tag: noindex, nofollow
< X-Content-Type-Options: nosniff
< X-XSS-Protection: 1; mode=block
< Referrer-Policy: strict-origin-when-cross-origin
< WWW-Authenticate: Bearer realm="Example Service", scope="client.example.api"
< Content-Type: text/html;charset=utf-8
< Cache-Control: must-revalidate,no-cache,no-store
< Content-Length: 246
<



Error 401 Unauthorized

</head>
<body><h2>HTTP ERROR 401</h2>
<p>Problem accessing /dossiers. Reason:
<pre> Unauthorized</pre></p>
</body>
</html>
* Connection #0 to host dev01.example.com left intact
* Closing connection 0

I printed the wrong thing to the console (:man_facepalming:), but this being said, this points to what area of core-foundation's URLSession might be at fault, for the purpose of a bug report. Your code works as expected if you go use a URL that either doesn't exist or is public.

Yeah I also think it's related with authorisation. Expired tokens also causes the same error on linux.

Are you sure the issue isn’t that you’re blocking the main thread while you call sleep()? Try something like this:

import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

print("Hello, world!")
let session = URLSession.shared
let url = URL(string: "https://dev01.signicat.com/assure/dossiers")!

let semaphore = DispatchSemaphore(value: 0)

let task = session.dataTask(with: url) { data, response, error in
    print("Goodbye, world!")
    semaphore.signal()
}
print("1. Task state: \(task.state.rawValue)")
task.resume()

print("2. Task state: \(task.state.rawValue)")

semaphore.wait()

print("3. Task state: \(task.state.rawValue)")