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

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

Closed
swift-ci opened this issue Apr 3, 2019 · 2 comments

Comments

@swift-ci
Copy link
Contributor

swift-ci commented Apr 3, 2019

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),
    ]
}
@swift-ci
Copy link
Contributor Author

swift-ci commented Apr 3, 2019

Comment by sai Hema k (JIRA)

The failure is due to the invocation of the Taskregistry.remove twice when the response code is not equal to 401.

@swift-ci
Copy link
Contributor Author

swift-ci commented Apr 4, 2019

Comment by Ian Partridge (JIRA)

#2061

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant