-
-
Notifications
You must be signed in to change notification settings - Fork 76
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
Memory leak in version 1.22.0 #496
Comments
Repro (No need to even do a query): @main
struct EntryPoint {
static func main() async throws {
let config = PostgresClient.Configuration(...)
let client = PostgresClient(configuration: config)
try await withThrowingTaskGroup(of: Void.self) { taskGroup in
taskGroup.addTask {
await client.run()
}
taskGroup.addTask {
for idx in (0..<100_000) {
if idx % 10 == 0 {
print(idx)
}
try await Task.sleep(for: .milliseconds(10))
try await client.withConnection { conn in
/// No need to even do a query
}
}
}
try await taskGroup.waitForAll()
}
}
} |
No need to even be able to create a proper connection?: @main
struct EntryPoint {
static func main() async throws {
let config = PostgresClient.Configuration(
host: "CORRECT-HOST",
port: 5432,
username: "USER",
password: "BAD_PASSWORD",
database: "DB",
tls: .disable
)
let client = PostgresClient(configuration: config)
try await withThrowingTaskGroup(of: Void.self) { taskGroup in
taskGroup.addTask {
await client.run()
}
taskGroup.addTask {
for idx in (0..<100_000) {
if idx % 10 == 0 {
print(idx)
}
try await Task.sleep(for: .milliseconds(10))
try await client.withConnection { conn in
}
}
}
try await taskGroup.waitForAll()
}
}
} |
Okay, found the source of this leak: With
However in the success case we never forward them to the wire in the PostgresChannelHandler.
|
Would it maybe make sense to revert the commit that has caused the leak before the fix PR is approved and merged in? |
@LukasCZ thanks for pinging. Will prepare a revert pr for now. |
PR is up: #501 |
Released as 1.22.1 |
Thank you @fabianfett 🙏 |
Describe the issue
Memory usage spiked when we deployed our application with postgres-nio 1.22.0.
Vapor version
4.102.1
Operating system and version
Linux
Swift version
Swift 5.10
Steps to reproduce
Run a Swift backend application that uses postgres-nio and compare the memory usage when on 1.21.5 and 1.22.0.
Outcome
Memory usage steadily increases after starting an application that uses postgres-nio 1.22.0.
Additional notes
We observed this on an instance that runs recurring jobs but does not receive web traffic, so memory usage tends to be stable over time.
In the attached screenshot, the first release to include postgres-nio 1.22.0 was on July 26. The sudden drops in memory usage indicate when new releases went live, restarting the app. The graph stabilizes on July 30 when we reverted postgres-nio to 1.21.5.
Edit: I'm not sure if the memory usage spikes in 1.21.6 or 1.22.0.
The text was updated successfully, but these errors were encountered: