Hi all,
thank you all for your advice. I've been investigating this a little more and finally it turned out it's not a bug in libpq although I got confused by going deep as several libpq functions. The bug was really on our side after trying to use connection pointer after calling PQfinish(). The code is pretty complex so it took some time to investigate however I would like to apologize for "blaming" libpq instead of our code.
Anyway, thank you all for valuable advice.
Have a great time,
Michal