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

Add Async Storage shutdown #3196

Merged
merged 10 commits into from
May 24, 2024
Merged

Add Async Storage shutdown #3196

merged 10 commits into from
May 24, 2024

Conversation

0xTim
Copy link
Member

@0xTim 0xTim commented May 21, 2024

These changes are now available in 4.101.0

Currently running

Task {
    try? await Task.sleep(for: .seconds(5))
    app.running?.stop()
}

When you try and install NIO as the global executor will crash because the storage API didn't have any async entry points so stopping would trigger a synchronous shutdown, with a wait(). This fixes that

@0xTim 0xTim requested a review from gwynne as a code owner May 21, 2024 10:52
Copy link
Member

@gwynne gwynne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A nit and a question, but nothing blocking. I find this incredibly ugly and kinda concerningly fragile, but I have no better suggestions 😕

Sources/Vapor/Commands/ServeCommand.swift Outdated Show resolved Hide resolved
Comment on lines 14 to 28
var onAsyncShutdown: (@Sendable (T) async throws -> ())?
func shutdown(logger: Logger) {
do {
try self.onShutdown?(self.value)
} catch {
logger.warning("Could not shutdown \(T.self): \(error)")
}
}
func asyncShutdown(logger: Logger) async {
do {
try await self.onAsyncShutdown?(self.value)
} catch {
logger.warning("Could not shutdown \(T.self): \(error)")
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a better suggestion, but this seems incredibly error-prone/easy to misuse 😕

Sources/Vapor/Utilities/Storage.swift Show resolved Hide resolved
public var asyncShared: HTTPClient {
get async {
let lock = self.application.locks.lock(for: Key.self)
lock.lock()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes me uneasy but I don't see a way around it - any thoughts?

0xTim and others added 2 commits May 21, 2024 12:29
Co-authored-by: Gwynne Raskind <gwynne@vapor.codes>
@0xTim 0xTim added the semver-patch Internal changes only label May 21, 2024
@0xTim 0xTim requested a review from gwynne May 21, 2024 12:40
@0xTim
Copy link
Member Author

0xTim commented May 21, 2024

Ok @gwynne I've tested this with client calls as well and think I've fixed all the different areas without breaking the API too much

@0xTim 0xTim added semver-minor Contains new API and removed semver-patch Internal changes only labels May 24, 2024
@0xTim 0xTim merged commit cc98361 into main May 24, 2024
14 checks passed
@0xTim 0xTim deleted the storage-shutdown-async branch May 24, 2024 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-minor Contains new API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants