Skip to content

This Project is examining when segmentation fault by URLSession on Linux.

License

Notifications You must be signed in to change notification settings

iq3addLi/USSegFault

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

USSegFault


❗️I looked up this problem is solved on DEVELOPMENT-SNAPSHOT-2017-02-09-a.😁


This Project is examining when segmentation fault by URLSession on Linux. It is no happen on macOS and iOS.

I found it when I was writing this library

Sended bug report.

Environment at problem discovery

key value
OS Ubuntu 16.04
Swift 3.0.1
Build Debug and Release

What of problem?

If an error is contained in the completionHandler of URLSessionDataTask, passing it to the local variable across block will destroy the contents of Optional and generate a segmentation fault when accessing.

let session = URLSession(configuration: URLSessionConfiguration.default, delegate:nil, delegateQueue: nil)
let semaphore = DispatchSemaphore(value: 0) // Force synchronize
    
var data:Data?,response:URLResponse?,error:Swift.Error?
let subtask = session.dataTask(with: request) { (d, r, e) in
    data = d; response = r; error = e;
    semaphore.signal()
}
subtask.resume()
let _ = semaphore.wait(timeout: DispatchTime.distantFuture)
if let error = error {
    print("\(error)") // Segmentetion fault on Linux
}else{
    print("Test failed.")
}

Execute log on EC2

ubuntu@ip-*:~/USSegFault$ swift build
ubuntu@ip-*:~/USSegFault$ .build/debug/USSegFault
Segmentation fault (core dumped)
ubuntu@ip-*:~/USSegFault$ swift build -c release
Compile Swift Module 'USSegFault' (1 sources)
Linking ./.build/release/USSegFault
ubuntu@ip-*:~/USSegFault$ .build/release/USSegFault
Segmentation fault (core dumped)

Resolution

  • I want URLSession to have synchronization processing.
  • Since problems do not occur in iOS and macOS, please correct it in the same way.

Thanks!

About

This Project is examining when segmentation fault by URLSession on Linux.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages