Skip to content

[SR-10281] Kitura application crashes when the server returns a 401 unauthorized code  #3495

Closed
@swift-ci

Description

@swift-ci
Previous ID SR-10281
Radar None
Original Reporter saiHema (JIRA User)
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 1
Component/s Foundation
Labels Bug
Assignee saiHema (JIRA)
Priority Medium

md5: fb2a181801db3c18819818030ea60af6

Issue Description:

Application crashes with the following Fatal error :

Fatal error: Trying to remove task, but it's not in the registry.: file /swift-corelibs-foundation/Foundation/URLSession/TaskRegistry.swift, line 76

// Recreate

import XCTest
import Kitura
import Foundationfinal class dataTaskTests: XCTestCase {
    let router = Router()
    
    func testExample() throws {
        router.get("/", handler: getHandler)
        Kitura.addHTTPServer(onPort: 8080, with: router)
        Kitura.start()
        
        let expectation1 = expectation(description: "A unauthorized response is received from the server -> .unauthorized")     let request = URLRequest(url: URL(string: "http://localhost:8080/")!)
        let session = URLSession(configuration: URLSessionConfiguration.default)
        let task = session.dataTask(with: request) { (data, response, error) in
            print("session.dataTask: \(String(describing: response?.description))")
            guard error == nil, let response = response as? HTTPURLResponse else {
                print("Error returned: \(String(describing: error?.localizedDescription))")
                return XCTFail("Error connecting returned")
            }
            
            let code = response.statusCode
            if code >= 200 && code < 300 {
                print("Success code")
                return XCTFail()
            } else {
                print("Failure code")
                expectation1.fulfill()
            }
        }
        task.resume()
        waitForExpectations(timeout: 3.0, handler: nil)
        Kitura.stop()
    }   func getHandler(completion: ([String]?, RequestError?) -> Void) {
        completion(nil, .unauthorized)
    }    static var allTests = [
        ("testExample", testExample),
    ]
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions