URLSession on Linux giving different result than on iOS
Asked Answered
L

0

7

I've got a simple class making a HTTP POST request (to a Neo4j server, but that shouldn't matter) using URLSession, and an integration test that tests that it succeeds.

Through Xcode, via the iOS simulator, I can run this test a million times - it succeeds every time.

However, when I run swift test on Ubuntu Linux (I use the docker image provided by IBM) then I very often will get a test failure saying I got a 401 response.

Replicating that via cURL in the container does not fail at all, so I do not believe this to be a problem with my container.

I have added a packet dump (that I inspect via Charles Proxy) where our of 15 test runs, 7 test runs (and thus 7 requests) fail. All of the failed requests complain that no authentication header was supplied. And from the dump, that is correct, the dump does not contain the authentication header for those requests that fail. But why not? In fact, all of the header flags are different: a successful run has these headers:

POST /db/data/cypher HTTP/1.1
Host: 192.168.0.18:7474
Accept-Encoding: deflate, gzip
Authorization: Basic bmVvNGo6c3RhY2swdmVyRmxvdw==
Content-Type: application/json; charset=utf-8
Accept: application/json; charset=utf-8
Connection: keep-alive
User-Agent: urlsessionTestPackageTests.xctest (unknown version) curl/7.35.0
Content-Length: 135

while an unsuccessful one has these:

POST /db/data/cypher HTTP/1.1
Host: 192.168.0.18:7474
Accept: */*
Accept-Encoding: deflate, gzip
Connection: keep-alive
User-Agent: urlsessionTestPackageTests.xctest (unknown version) curl/7.35.0
Content-Length: 135

All the 200 results have the same headers, and all the 401 results have the same headers. Can you see anything in my code that should warrant such a random request?

Lonnie answered 11/1, 2017 at 22:27 Comment(3)
Seems similar to #41230314 - the container Swift version is 3.0.1Lonnie
I updated to Swift 3.0.2, still same error. So I adjusted the code as suggested above, and got only 5 errors out of 62 requests. Much better, but it still fails and I still don't know why.Lonnie
Issue persists with the now official Docker image with 16.04: github.com/swiftdocker/docker-swiftLonnie

© 2022 - 2024 — McMap. All rights reserved.