Kitura / Swift-Kuery-ORM

An ORM for Swift, built on Codable
Apache License 2.0
212 stars 30 forks source link

TableInfo.codableMap is not thread-safe #63

Closed djones6 closed 6 years ago

djones6 commented 6 years ago

Context and Description

When running a benchmark with multiple concurrent connections, I get a crash in TableInfo.getInfo(), where codableMap["\(type)"] is being force-unwrapped:

https://github.com/IBM-Swift/Swift-Kuery-ORM/blob/master/Sources/SwiftKueryORM/TableInfo.swift#L37

The code should have ensured it was initialized if it was initially nil, however if multiple threads execute this for the same type, we can end up unwrapping a nil value.

The assignment of this map should be made thread-safe.

Environment Details

Information about your OS, Swift version and Xcode version if on macOS.

Steps to Reproduce

1) ... 2) ...

Expected vs. Actual Behaviour