vincentneo / CoreGPX

A library for parsing and creation of GPX location files. Purely Swift.
https://www.vincent-neo.com
MIT License
261 stars 57 forks source link

Potential concurrency issue in DateTimeParsers.swift #101

Open ClementCardonnel opened 1 year ago

ClementCardonnel commented 1 year ago

Hi!

I've recently encountered a crash in DateTimeParsers.swift.

My crash occurred on line 81:

Self.calendarCache[0] = calendar

Which references this static variable:

private static var calendarCache = [Int : Calendar]()

I was parsing multiple GPX files inside Swift.Tasks. I believe this crash is concurrency driven where multiple threads attempted to access the same static variable.

Could thread safety be improved by using for example an Actor? Or should I consider CoreGPX not thread safe and try to always parse my GPX files sequentially?

Thanks in advance

vincentneo commented 1 year ago

Could thread safety be improved by using for example an Actor?

Maybe it would, but it's probably safest to treat CoreGPX in its current form as not thread safe.