File tree Expand file tree Collapse file tree 1 file changed +15
-5
lines changed
Sources/PostgresClientKit Expand file tree Collapse file tree 1 file changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -1120,12 +1120,22 @@ public class Connection: CustomStringConvertible {
11201120 readBufferPosition = 0
11211121
11221122 var readCount = 0
1123+ let timeout = Date ( timeIntervalSinceNow: 30.0 ) // 30 seconds
11231124
1124- do {
1125- readCount = try socket. read ( into: & readBuffer)
1126- } catch {
1127- log ( . warning, " Error receiving response: \( error) " )
1128- throw PostgresError . socketError ( cause: error)
1125+ while readCount == 0 && Date ( ) < timeout && !socket. remoteConnectionClosed {
1126+ do {
1127+ readCount = try socket. read ( into: & readBuffer)
1128+
1129+ if readCount == 0 {
1130+ // Workaround https://github.com/IBM-Swift/BlueSSLService/issues/79.
1131+ // This issue results in socket.read(...) returning 0 even though the
1132+ // socket is supposedly "blocking".
1133+ Thread . sleep ( forTimeInterval: 0.01 ) // 10 ms
1134+ }
1135+ } catch {
1136+ log ( . warning, " Error receiving response: \( error) " )
1137+ throw PostgresError . socketError ( cause: error)
1138+ }
11291139 }
11301140
11311141 if readCount == 0 {
You can’t perform that action at this time.
0 commit comments