PerfectlySoft / Perfect

Server-side Swift. The Perfect core toolset and framework for Swift Developers. (For mobile back-end development, website and API development, and more…)
https://www.perfect.org
Apache License 2.0
13.84k stars 945 forks source link

when i was send request with for i in 0..<2 {Alamofire.request(.....)} #250

Open cxr0715 opened 6 years ago

cxr0715 commented 6 years ago

when i was send request with

for i in 0..<2 {
       //client send
       //and server will run: self.mysql.query(statement: "select * from home")
       Alamofire.request(.....)
}

have a crash happened

and send only one request Alamofire.request(.....),server is done

qq20180427-014657 2x
kjessup commented 6 years ago

Are you using a global MySQL connection or sharing them amongst threads in any way? Sharing one connection is definitely not thread-safe.

cxr0715 commented 6 years ago

but I use MySQLManager connected is Singleton whit thread-safe

class MySQLManager {
    var mysql : MySQL!
    static let shareInstance : MySQLManager = {
        let instance = MySQLManager()
        let testHost = "127.0.0.1"
        let testUser = "root"
        let testPassword = "********"
        let testDB = "********"
        instance.mysql = MySQL()
        let connected = instance.mysql.connect(host: testHost, user: testUser, password: testPassword, db: testDB)

        if connected {
            print("connectedSuccess")
        } else {
            print("connectedError")
        }

        guard connected else {
            print(instance.mysql.errorMessage())
            return instance
        }
        return instance
    }()
    private init(){}

}
kuhl commented 5 years ago

A "use of undeclared type" usually means you have a linker error. Check your target. I don't think this is an issue in Perfect. Please close.