You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Application crash because of a req.auth.require(Something.self)
Vapor version
4.84.2
Operating system and version
macos 14.4.1 (23E224) apple m2
Swift version
Swift Package Manager - Swift 5.10.0-dev
Steps to reproduce
create a simple Vapor application and use this as handle and build in release mode.
structTest:Authenticatable{}func test(req:Request)asyncthrows->Response{awaitwithThrowingTaskGroup(of:Void.self){ group in
for i in (0...5){
group.addTask{try? req.auth.require(Test.self)}}}return.init()}
call the handle, usually around the second call it crashes.
I've dug into the code and I've found that the problem is the following pattern inside a concurrently executing code
if let existing = req.storage.get(Test.self){
req.logger.info("get")}else{
req.storage[Test.self]=.init()
req.logger.info("Set")}
if let existing =self.request.storage[CacheKey.self]{
return existing
}else{
letnew=Cache()
self.request.storage[CacheKey.self]= new
return new
}
}
set{
self.request.storage[CacheKey.self]= newValue
}
}
Something like this fixes the issue, but I suppose it's too simple of a solution and also I don't know the performances impact it may have.
letlock:NIOLock=.init()
lock.withLock{
if let existing = req.storage.get(Test.self){
req.logger.info("get")}else{
req.storage[Test.self]=.init()
req.logger.info("Set")}}
Outcome
The program goes boom 😄
Additional notes
The same issue arises in an amazon linux 2 container with swift 5.7
The text was updated successfully, but these errors were encountered:
Describe the issue
Application crash because of a
req.auth.require(Something.self)
Vapor version
4.84.2
Operating system and version
macos 14.4.1 (23E224) apple m2
Swift version
Swift Package Manager - Swift 5.10.0-dev
Steps to reproduce
create a simple Vapor application and use this as handle and build in release mode.
call the handle, usually around the second call it crashes.
I've dug into the code and I've found that the problem is the following pattern inside a concurrently executing code
This is exactly what we find here
vapor/Sources/Vapor/Authentication/AuthenticationCache.swift
Lines 84 to 97 in 11cdb29
Something like this fixes the issue, but I suppose it's too simple of a solution and also I don't know the performances impact it may have.
Outcome
The program goes boom 😄
Additional notes
The same issue arises in an amazon linux 2 container with swift 5.7
The text was updated successfully, but these errors were encountered: