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-14879] Calendar not thread-safe in swift-corelibs-foundation #3217

Closed
ffried opened this issue Jul 6, 2021 · 1 comment
Closed

[SR-14879] Calendar not thread-safe in swift-corelibs-foundation #3217

ffried opened this issue Jul 6, 2021 · 1 comment
Assignees

Comments

@ffried
Copy link
Contributor

ffried commented Jul 6, 2021

Previous ID SR-14879
Radar None
Original Reporter @ffried
Type Bug
Status Closed
Resolution Duplicate
Environment

Docker image: swift:5.4.2-focal
Swift version 5.4 (swift-5.4-RELEASE)
Target: x86_64-unknown-linux-gnu

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee @ffried
Priority Medium

md5: 0eb37680f4fb29e7176edb2f77dddea0

duplicates:

Issue Description:

Calendar in swift-corelibs-foundation seems to have a thread-safety issue that is not present in Darwin Foundation.
The following code works fine on Darwin but crashes on Linux:

import Foundation

func makeCalendar() -> Calendar {
   var cal = Calendar(identifier: .gregorian)
   cal.timeZone = .init(secondsFromGMT: 0)!
   return cal
}

let calendar = makeCalendar()
// If a new calendar is created on every access, things work fine.
//var calendar: Calendar { makeCalendar() }

DispatchQueue.concurrentPerform(iterations: 50) { iter in
   _ = calendar.startOfDay(for: Date())
}

If the let calendar = ... is replaced by the computed var two lines below, the code works fine on linux as well.

Backtrace of the execution on linux:

* thread #​2, name = 'StartOfToday', stop reason = signal SIGILL: illegal instruction operand
  * frame #​0: 0x00007ffff7ac868b libFoundation.so`Foundation.DateInterval.init(start: Foundation.Date, duration: Swift.Double) -> Foundation.DateInterval + 11
    frame #&#8203;1: 0x00007ffff7b6a3b5 libFoundation.so`Foundation.NSCalendar.range(of: Foundation.NSCalendar.Unit, for: Foundation.Date) -> Swift.Optional<Foundation.DateInterval> + 117
    frame #&#8203;2: 0x00007ffff7b6ba40 libFoundation.so`Foundation.NSCalendar.startOfDay(for: Foundation.Date) -> Foundation.Date + 16
    frame #&#8203;3: 0x00007ffff7a90fd4 libFoundation.so`partial apply forwarder for closure #&#8203;1 (Foundation.NSCalendar) -> Foundation.Date in Fouandation.Calendar.startOfDay(for: Foundation.Date) -> Foundation.Date + 20
    frame #&#8203;4: 0x00007ffff7a90ff1 libFoundation.so`partial apply forwarder for reabstraction thunk helper from @callee_guaranteed (@guaranteed Foundation.NSCalendar) -> (@unowned Foundation.Date, @error @owned Swift.Error) to @escaping @callee_guaranteed (@guaranteed Foundation.NSCalendar) -> (@out Foundation.Date, @error @owned Swift.Error) + 17
    frame #&#8203;5: 0x00007ffff7a80337 libFoundation.so`Foundation._MutableHandle.map<τ_0_0>((τ_0_0) throws -> τ_1_0) throws -> τ_1_0 + 71
    frame #&#8203;6: 0x00007ffff7a8c777 libFoundation.so`Foundation.Calendar.startOfDay(for: Foundation.Date) -> Foundation.Date + 71
    frame #&#8203;7: 0x0000555555555035 StartOfToday`closure #&#8203;1 (Swift.Int) -> () in StartOfToday + 69
    frame #&#8203;8: 0x00007ffff70c353c libswiftDispatch.so`partial apply forwarder for reabstraction thunk helper from @callee_guaranteed (@unowned Swift.Int) -> () to @escaping @callee_guaranteed (@unowned Swift.Int) -> () + 12
    frame #&#8203;9: 0x00007ffff70c354f libswiftDispatch.so`reabstraction thunk helper from @escaping @callee_guaranteed (@unowned Swift.Int) -> () to @callee_unowned @convention(block) (@unowned Swift.Int) -> () + 15
    frame #&#8203;10: 0x00007ffff7064a6e libdispatch.so`_dispatch_apply_invoke + 190
    frame #&#8203;11: 0x00007ffff707bcf7 libdispatch.so`_dispatch_worker_thread + 903
    frame #&#8203;12: 0x00007ffff723d609 libpthread.so.0`start_thread + 217
    frame #&#8203;13: 0x00007ffff6f2e293 libc.so.6`__clone + 67
@ffried
Copy link
Contributor Author

ffried commented Jul 6, 2021

Ah, found an existing report for this. Closing as dupe.

@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