Bug 371331 - database calls randomly fail on Windows 10 (postgresql)
Summary: database calls randomly fail on Windows 10 (postgresql)
Status: CLOSED FIXED
Alias: None
Product: KDb
Classification: Frameworks and Libraries
Component: Driver: PostgreSQL (show other bugs)
Version: 3.0.0
Platform: Compiled Sources Microsoft Windows
: NOR normal
Target Milestone: 3.0.1
Assignee: Jarosław Staniek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-10-20 16:00 UTC by Simeon Kuran
Modified: 2016-10-26 01:17 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In: 3.0.1
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Simeon Kuran 2016-10-20 16:00:37 UTC
I wrote a simple test application, just to try the KDb library on a Windows 10 system.
I compiled KF5 packages (5.24) and KDb 3.0.0 (and Kexi) from source using MSVC 2013 64 bit compiler.

I use my test application to connect to a postgresql DB on localhost (I installed PostgreSql 9.5 64 bit for Windows 10). But somehow the database calls randomly fail! Maybe there is a bug in the postgresql driver plugin, I guess ?

My test application first connects to the PostgreSql Server and then lists all available databases found. Next it executes connection->useDatabase() on a specific database and executes a SQL select statement. Sometimes no databases appear, sometimes the useDatabase() call fails and sometimes I have even the impression, that not all SQL records are delivered (but a subset of it).

I CAN EVEN OBSERVE THE SAME BEHAVIOUR WITH KEXI (compiled from source). I need several tries to connect to my postgresql server and open a previously saved project. I need "to be lucky", so that all database calls work, then the project is opened as it should be. But most of the time one (or more) of the database calls seem to fail even in Kexi, at least in my setup.

If you need more information, please contact me!
If it helps, I could e.g. upload my sample project, but I would have to clean up some parts first...
Tell me, if I could help in anyway...

Thanks!
Comment 1 Jarosław Staniek 2016-10-20 16:05:39 UTC
Thanks Simeon. It would help if you link to your test app's code and place where it fails. Having more public test apps is always a good idea.
Comment 2 Simeon Kuran 2016-10-21 08:06:15 UTC
I thought so... I will upload it to some git repo, but I will need some time! Hopefully I can do it on the weekend...
Comment 3 Jarosław Staniek 2016-10-21 09:22:32 UTC
Simeon, you can also quickly email me zipped files, no problem.
Comment 4 Simeon Kuran 2016-10-21 13:11:04 UTC
I just finished cleaning up my project and uploaded it to my bitbucket account.
I also added a zip archive (kdb-test-binary) which contains the compiled executable with all necessary dll files (except msvc runtime dlls).  (size of the zip archive is probably to big for email...)

to get it:
git clone git@bitbucket.org:simeonKuran/kdb-test.git

IMPORTANT:
I need to point out once more, that sometimes everything works as expected! But sometimes one or the other DB calls seem to fail. Kind of non-deterministic it seems to me...

Of course to try it out, you will need a postgresql DB. I think I installed version 9.5.4 - 64bit from this link: http://www.enterprisedb.com/products-services-training/pgdownload#windows
Comment 5 Jarosław Staniek 2016-10-21 13:43:44 UTC
> sometimes one or the other DB calls seem to fail.

Is this KDbConnection::executeQuery() maybe?

On failure I recommend to use qDebug() << m_connection->result() so we know what happens.
Similarly, KDbCursor also has result() method.
Comment 6 Simeon Kuran 2016-10-21 15:57:35 UTC
No, I don't think so!
Most of the time, the error occurs far before executing the SQL SELECT statement!
I have to admit, that it's hard to debug, because sometimes all works as it should. I needed several attempts too, but then I got the following error on console:

"using database failed:  KDbResult: OK" 

When executing the following piece of code:

  bool cancelled;
  bool ok = m_connection->useDatabase(database, KEXI_COMPATIBLE, &cancelled);

  if (ok)
  {
    qDebug() << "using DB '" << database << "'." << endl;

    emit databaseAvailable(database);
  }
  else
  {
    qDebug() << "using database failed: " << m_connection->result();
  }

In Kexi the situation is much worse: Opening a project only works by a chance of 1 to 5 or so... (the other 4 times it fails with different error messages). I am quite sure this is because Kexi of course fires much more PostgreSql / DB commands and one or the other just fails.

Shall I add my Kexi binaries to the git repo too? Maybe it would be interesting whether you can see the described effects too with it? .... Though I know that I didn't set up KReport correctly, but at the moment I don't need it and I am sure it doesn't affect this error. In Kexi such DB errors show up quite frequently when I create a new project, add some simple tables, store the project and then try to reopen it.

I know this comment sounds a bit like if my incomplete setup of Kexi causes the error, but I am quite sure that's not the case. I am very convinced, that the error happens in KDb (at least in my self compiled KDb version. I don't want to blame KDb for it though. I can not / and don't want to exclude, that I simply did something wrong! )

Thanks for your efforts!
Comment 7 Jarosław Staniek 2016-10-21 18:50:59 UTC
Thanks for the report.
Binaries are not needed, at least I don't use them.

Before we find solution could you please try:
1. to use the SQLite db type for your work
2. to use the MySQL db type for your work

And tell me if you encounter any issues.

Please also try in you app KEXI_COMPATIBLE == true at https://bitbucket.org/simeonKuran/kdb-test/src/5098cbad5d0a95694102fda03ab734cc6298fd7b/connection_widget.cpp?at=master&fileviewer=file-view-default
Comment 8 Simeon Kuran 2016-10-22 14:32:46 UTC
I tried Kexi with SQLite and MySQL now and they both worked! The error happens only with the PostgreSQL plugin! 

Also I tried using KEXI_COMPATIBLE = true in my app, but that didn't change anything.
Comment 9 Jarosław Staniek 2016-10-25 16:43:53 UTC
Good news. We had uninitialized variable just for the PostgreSQL driver. Will be fixed today in master and 3.0 git branch so you can get it immediately. And it will go to the 3.0.1 release.
Comment 10 Simeon Kuran 2016-10-25 17:26:56 UTC
Wow, I'm glad to hear that!
Good work! Thanks for your engagement :)
Comment 11 Jarosław Staniek 2016-10-25 18:07:03 UTC
Git commit 8f1a6ce31b7d12199669bff0effb5925115663a4 by Jaroslaw Staniek.
Committed on 25/10/2016 at 18:01.
Pushed by staniek into branch 'master'.

Fix database cursors for PostgreSQL: remove use of uninitialized variable

M  +0    -2    src/KDbCursor.h
M  +1    -1    src/drivers/postgresql/PostgresqlCursor.cpp

http://commits.kde.org/kdb/8f1a6ce31b7d12199669bff0effb5925115663a4
Comment 12 Jarosław Staniek 2016-10-25 18:20:31 UTC
OK Simeon, are you able to test the 3.0 and/or master branch?
Thanks.
Comment 13 Simeon Kuran 2016-10-26 00:45:58 UTC
I tested the master branch with Kexi. Now it works ! :)
Comment 14 Jarosław Staniek 2016-10-26 01:17:07 UTC
Super cool. Thanks.