PhoneNumberKit icon indicating copy to clipboard operation
PhoneNumberKit copied to clipboard

Data race runtime issue + Capture of 'buffer' with non-sendable type Warning

Open aiFigueiredo opened this issue 1 year ago • 1 comments

New Issue Checklist

  • [x] Updated PhoneNumberKit to the latest version
  • [x] Phone number formatted correctly on JavaScript version
  • [x] I searched for existing GitHub issues
  • [x] I am aware that this library is not responsible of adding/removing/changing phone number formats and any request should be done at libphonenumber repo

Steps to reproduce

The following code in a concurrent background thread produces a data race when the Thread Sanitizer is enabled:

struct ContactData {
    let number: [String]
}

let utility = PhoneNumberUtility()
let dataArray: [ContactData] = [...]

for item in dataArray {
    utility.parse(item.numbers)
}
Expected result

No warning, nor data race.

Actual result
  1. There is a data race accessing the hasError property: Screenshot 2024-12-19 at 22 15 41
Data race in closure #1 @Sendable (Swift.Int) -> () in closure #1 (inout Swift.UnsafeMutableBufferPointer<PhoneNumberKit.PhoneNumber>, inout Swift.Int) -> () in PhoneNumberKit.ParseManager.parseMultiple(_: Swift.Array<Swift.String>, withRegion: Swift.String, ignoreType: Swift.Bool, shouldReturnFailedEmptyNumbers: Swift.Bool) -> Swift.Array<PhoneNumberKit.PhoneNumber>

2, Opening the Project in Xcode 16.1 on master, shows a warning on line 112: Screenshot 2024-12-19 at 22 14 27

Capture of 'buffer' with non-sendable type 'UnsafeMutableBufferPointer<PhoneNumber>' in a `@Sendable` closure; this is an error in the Swift 6 language mode

Environment

Xcode 16.1 + SPM (v4.0.1 / master)

aiFigueiredo avatar Dec 19 '24 22:12 aiFigueiredo

Hey @bguidolim, let me know if there is something I missed on this 🙏

aiFigueiredo avatar Jan 08 '25 17:01 aiFigueiredo

Fixed with #826

Thanks for your contribution @aiFigueiredo

bguidolim avatar Jun 11 '25 20:06 bguidolim