-
-
Notifications
You must be signed in to change notification settings - Fork 77
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
Fix leakage of promises #497
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #497 +/- ##
==========================================
+ Coverage 55.12% 55.17% +0.05%
==========================================
Files 127 127
Lines 10174 10207 +33
==========================================
+ Hits 5608 5632 +24
- Misses 4566 4575 +9
|
Not sure how exactly add a test for this. let options = XCTMeasureOptions.default
options.iterationCount = 100
measure(metrics: [XCTMemoryMetric()], options: options) {
do {
let conn = try PostgresConnection.test(on: self.eventLoop).wait()
_ = try conn.query(
"SELECT current_setting('application_name')",
logger: .psqlNoOpLogger
).wait()
try conn.close().wait()
} catch {
XCTFail(String(reflecting: error))
}
} could work but it's too integrated into Xcode. Looks like a case that needs benchmarking, like with package-benchmark. |
Sources/PostgresNIO/New/Connection State Machine/ConnectionStateMachine.swift
Outdated
Show resolved
Hide resolved
@fabianfett another round of review please 🙂 |
afc12db
to
7aaae6e
Compare
Sources/PostgresNIO/New/Connection State Machine/AuthenticationStateMachine.swift
Outdated
Show resolved
Hide resolved
switch queryContext.query { | ||
case .executeStatement(_, let promise), .unnamed(_, let promise): | ||
return .failQuery(promise, with: psqlErrror, cleanupContext: nil) | ||
case .prepareStatement(_, _, _, let promise): | ||
return .failPreparedStatementCreation(promise, with: psqlErrror, cleanupContext: nil) | ||
} | ||
case .closeCommand(let closeContext): | ||
case .closeCommand(let closeContext, let writePromise): | ||
writePromise?.fail(psqlErrror) /// Use `cleanupContext` or not? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment
Sources/PostgresNIO/New/Connection State Machine/ConnectionStateMachine.swift
Outdated
Show resolved
Hide resolved
let action = self.state.enqueue(task: task) | ||
self.run(action, with: context) | ||
} | ||
|
||
case .failure(let error): | ||
let action = self.state.errorHappened(.unlistenError(underlying: error)) | ||
self.run(action, with: context) | ||
writePromise?.fail(error) /// Should I pass the promise to the action? seemed troublesome |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment
), | ||
logger: preparedStatement.logger, | ||
promise: preparedStatement.promise | ||
writePromise: nil // Ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ignore?
Sources/PostgresNIO/New/Connection State Machine/AuthenticationStateMachine.swift
Outdated
Show resolved
Hide resolved
Sources/PostgresNIO/New/Connection State Machine/ConnectionStateMachine.swift
Outdated
Show resolved
Hide resolved
Sources/PostgresNIO/New/Connection State Machine/ConnectionStateMachine.swift
Outdated
Show resolved
Hide resolved
Sources/PostgresNIO/New/Connection State Machine/ConnectionStateMachine.swift
Outdated
Show resolved
Hide resolved
@@ -583,14 +583,16 @@ struct ConnectionStateMachine { | |||
} | |||
|
|||
switch task { | |||
case .extendedQuery(let queryContext): | |||
case .extendedQuery(let queryContext, let writePromise): | |||
writePromise?.fail(psqlErrror) /// Use `cleanupContext` or not? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment
} | ||
|
||
/// Not my code, but this is ignoring the last argument which is a promise? is that fine? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment
} | ||
|
||
writePromise?.succeed(()) /// Should we instead do smth like "whenAllSucceed"? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment
b966180
to
8b944b2
Compare
resolves #496