-
Notifications
You must be signed in to change notification settings - Fork 19
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
Cannot retrieved TEXT from the server #8
Comments
Here is the log output: 2019-07-17 22:19:40.152748-0400 Tello EHR[13454:8562686] PatientMstrDao.searchAllPatient started... The IMAGE is the one with datatype TEXT and the size of the data stored is 17.82 MB. |
The error indicates the Postgres server returned a response containing fewer bytes than expected. You might want to check the Postgres log file for an error message or other clues. I wrote a quick command-line test for your scenario. The contents of import Foundation
import PostgresClientKit
do {
var configuration = PostgresClientKit.ConnectionConfiguration()
configuration.host = "127.0.0.1"
configuration.ssl = true
configuration.database = "example"
configuration.user = "bob"
configuration.credential = .md5Password(password: "welcome1")
let connection = try PostgresClientKit.Connection(configuration: configuration)
defer { connection.close() }
var text = "DROP TABLE IF EXISTS foo"
try connection.prepareStatement(text: text).execute()
text = "CREATE TABLE foo (id INTEGER, image TEXT)"
try connection.prepareStatement(text: text).execute()
let id = 1
var imageBytes = [UInt8]()
for _ in 0..<20_000_000 {
imageBytes.append(UInt8.random(in: 0...255))
}
let imageData = Data(imageBytes).base64EncodedData(options: .lineLength64Characters)
let image = String(data: imageData, encoding: .ascii)!
text = "INSERT INTO foo VALUES ($1, $2)"
try connection.prepareStatement(text: text).execute(parameterValues: [ id, image ])
text = "SELECT * FROM foo"
let cursor = try connection.prepareStatement(text: text).execute()
for row in cursor {
let columns = try row.get().columns
let selectedId = try columns[0].int()
let selectedImage = try columns[1].string()
print("selected id \(selectedId) with a \(selectedImage.count) byte image")
assert(selectedId == id)
assert(selectedImage == image)
}
print("success!")
} catch {
print(error)
}
// EOF By the way, PostgresClientKit supports the Postgres bytea data type, which might be a more direct way to store image data. See the API doc for the PostgresByteA struct. |
Hello. Thanks for the reply. 2019-07-18 13:25:14.839 UTC [7863] LOG: received fast shutdown request It seems my application was disconnected to the server (connection is closed). Do you have any idea on why this occurred? I tried to increased tcp_keepalives_idle, but it still not solve the issue. Thank you and good day. |
I tried to check my application and found out the connection was closed after the query is executed. Here is my code `
` I tried to print out connection.isClosed before the execute statement and it returned FALSE. Is there any idea on why this happened? Thank you and good day. |
Additional Information: The code is working if I removed the image from the select statement. |
I tried your code also in my environment. Similar error occurred. Please see the following log: [2019-07-18T14:33:09.459Z Connection-2 warning] Response truncated; no data available The only different between your implementation with mine is you are using the local database and I am using the remote database in AWS EC2. |
OK, thanks for the additional information. I am able to reproduce this problem when running an OSX client against a remote Linux server (running on a Linode, in my case). This appears to be bug. Either in the socket libraries used by PostgresClientKit (Kitura BlueSocket and BlueSSLService), or in how PostgresClientKit uses those libraries. I will continue to investigate this. I can only reproduce the problem for the SSL case. Could you please try disabling SSL ( Also, I can only reproduce the problem in SELECTing very long strings from the TEXT column. Could you please try INSERTing a shorter string (say, 1000 bytes) and SELECTing that? Let me know if that still produces an error. (Of course, long strings should work too, but this will help confirm we are looking at the same issue.) You mentioned the Connection is closed after the error occurs. This is expected behavior. When PostgresClientKit encounters a fatal error in communicating with the Postgres server, the connection is automatically closed. (A "fatal error" is one that prevents further use of the connection -- such as the socket being closed by the Postgres server, or a garbled or incomplete response.) Closing the connection in these cases lets the application know it needs to create a new connection, and lets the ConnectionPool know that the connection should not be returned to the pool. Thank you for your help in tracking down this issue. |
Hello. Thanks for the reply. I turned off the SSL on server side. (postgres.conf) This time, I can retrieved the long TEXT data from the database. But turning off the SSL both server and APP side eliminate the issue i reported here. Hope this help you to debug the issue. |
I have filed #10 to track the underlying problem. That issue links to another issue in the BlueSSLService library. If you are interested, there is a one-line change in BlueSSLService that seems to fix this problem. Thanks again for your help with this. |
Just released v0.3.2 which should fix this. |
I am creating an application which will upload an image from iPad to postgres server and also download the image data from database and display in iPad.
In my database, I have a column named image with TEXT data type.
In my application, I converted the image to string data using base64EncodedString(options: .lineLength64Characters) method.
The upload of the image data to database works well. However, an error occurred when I tried to select the data (including the image) from the database and here is the error message:
"Response truncated; no data available"
"no data available from server"
Can anyone help with this issue?
Thank you and good day
The text was updated successfully, but these errors were encountered: