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-7745] DateFormatter implemented in swift-corelibs-foundation isn't thread safe #50285

Closed
swift-ci opened this issue May 23, 2018 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. cloned Resolution: Was resubmitted in the appropriate repository rather than transferred crash Bug: A crash, i.e., an abnormal termination of software Foundation Linux Platform: Linux

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented May 23, 2018

Previous ID SR-7745
Radar None
Original Reporter gmilos (JIRA User)
Type Bug

Attachment: Download

Additional Detail from JIRA
Votes 3
Component/s Foundation
Labels Bug
Assignee None
Priority Medium

md5: 57280ba56625aceea6c47b821c76de92

Issue Description:

The following piece of code succeeds on Darwin, but fails on Linux:

import Foundation
import Dispatch

let currentDate = Date()
let formatter = ISO8601DateFormatter()
let dateStringLength = formatter.string(from: currentDate).count

DispatchQueue.concurrentPerform(iterations: 1000) { _ in
    let formatted = formatter.string(from: currentDate)
    if formatted.count != dateStringLength {
        print("Detected wrong date formatting: \(formatted)")
    }
}

On Linux, using swift-4.1-release it gives:

root@de03da451b4f:/Users/gmilos/Repos/DateFormatterThreadSafety# swift run
Compile Swift Module 'DateFormatterThreadSafety' (1 sources)
Linking ./.build/x86_64-unknown-linux/debug/DateFormatterThreadSafety
Detected wrong date formatting: 2018-0005-23T10:35:12Z
....
Detected wrong date formatting: 2018-05-0023T10:35:12Z
Detected wrong date formatting: 2018-05-23T10:35:0012Z
Detected wrong date formatting: 2018-05-23T0010:35:12Z

I'm attaching reproduction (simple SwiftPM project).

Note that the documentation specifies that date formatter has been thread safe for a while:

https://developer.apple.com/documentation/foundation/dateformatter

Thread Safety

On iOS 7 and later NSDateFormatter is thread safe.

In macOS 10.9 and later NSDateFormatter is thread safe so long as you are using the modern behavior in a 64-bit app.

While it doesn't explicitly talk about Linux (of course), this is the source of truth for most people.

@spevans
Copy link
Collaborator

spevans commented May 28, 2018

I tried this on Ubuntu 16.04 and could not reproduce with either

swift-4.1.1-RELEASE-ubuntu16.04 or

swift-DEVELOPMENT-SNAPSHOT-2018-05-26-a-ubuntu16.04

even if I boost the iterations to 100000.

If this is on Ubuntu 14.04 it could be an ICU issue

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@weissi
Copy link
Member

weissi commented Apr 29, 2022

CC @millenomi / @tomerd this is still causing issues: https://forums.swift.org/t/vapor-crash/56952

@weissi weissi added the run-time crash Bug → crash: Swift code crashed during execution label Apr 29, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
@AnthonyLatsis AnthonyLatsis added transfer candidate The issue may belong in another repository Linux Platform: Linux duplicate Resolution: Duplicates another issue and removed transfer candidate The issue may belong in another repository labels Jan 17, 2023
@AnthonyLatsis
Copy link
Collaborator

Closing this out as a dupe because the issue is already being tracked at swift-corelibs-foundation.

@AnthonyLatsis AnthonyLatsis added the off topic Resolution: Is beyond the scope of the Swift project (Xcode, proprietary Apple frameworks, etc.) label Jan 17, 2023
@AnthonyLatsis AnthonyLatsis added cloned Resolution: Was resubmitted in the appropriate repository rather than transferred and removed off topic Resolution: Is beyond the scope of the Swift project (Xcode, proprietary Apple frameworks, etc.) run-time crash Bug → crash: Swift code crashed during execution duplicate Resolution: Duplicates another issue labels May 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. cloned Resolution: Was resubmitted in the appropriate repository rather than transferred crash Bug: A crash, i.e., an abnormal termination of software Foundation Linux Platform: Linux
Projects
None yet
Development

No branches or pull requests

4 participants