Skip to content

Commit

Permalink
Fix #10 with workaround for underlying BlueSSLService issue
Browse files Browse the repository at this point in the history
  • Loading branch information
pitfield committed Jul 25, 2019
1 parent 54ef859 commit 98a2369
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions Sources/PostgresClientKit/Connection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1120,12 +1120,22 @@ public class Connection: CustomStringConvertible {
readBufferPosition = 0

var readCount = 0
let timeout = Date(timeIntervalSinceNow: 30.0) // 30 seconds

do {
readCount = try socket.read(into: &readBuffer)
} catch {
log(.warning, "Error receiving response: \(error)")
throw PostgresError.socketError(cause: error)
while readCount == 0 && Date() < timeout && !socket.remoteConnectionClosed {
do {
readCount = try socket.read(into: &readBuffer)

if readCount == 0 {
// Workaround https://github.com/IBM-Swift/BlueSSLService/issues/79.
// This issue results in socket.read(...) returning 0 even though the
// socket is supposedly "blocking".
Thread.sleep(forTimeInterval: 0.01) // 10 ms
}
} catch {
log(.warning, "Error receiving response: \(error)")
throw PostgresError.socketError(cause: error)
}
}

if readCount == 0 {
Expand Down

0 comments on commit 98a2369

Please sign in to comment.