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

Fix a retain cycle in PostgreSQLConnection #116

Merged
merged 1 commit into from
Feb 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Sources/PostgreSQL/Connection/PostgreSQLConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public final class PostgreSQLConnection: DatabaseConnection, BasicWorker, Databa
self.isClosed = false
self.extend = [:]
self.pipeline = channel.eventLoop.newSucceededFuture(result: ())
channel.closeFuture.always {
self.isClosed = true
if let current = self.currentSend {
channel.closeFuture.always { [weak self] in
self?.isClosed = true
if let current = self?.currentSend {
current.fail(error: closeError)
}
}
Expand Down
15 changes: 15 additions & 0 deletions Tests/PostgreSQLTests/PostgreSQLConnectionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,20 @@ class PostgreSQLConnectionTests: XCTestCase {
}
}
}

func testClosureRetainCycle() throws {
weak var connection: PostgreSQLConnection?
let request: EventLoopFuture<Void>
do {
let conn = try PostgreSQLConnection.makeTest()
request = conn.simpleQuery("SELECT true")
connection = conn
}
XCTAssertNotNil(connection)
try request.wait()
try request.eventLoop.future().wait()
XCTAssertNil(connection)
}

static var allTests = [
("testBenchmark", testBenchmark),
Expand All @@ -628,6 +642,7 @@ class PostgreSQLConnectionTests: XCTestCase {
("testEmptyArray", testEmptyArray),
("testZeroNumeric", testZeroNumeric),
("testNumericDecode", testNumericDecode),
("testClosureRetainCycle", testClosureRetainCycle),
]
}

Expand Down