It seems to me that the problem is in pqpath.c pq_get_last_result() function. The loop assumes PQgetResult won't block, which seems always the case with the direct connection, but PQisBusy() actually returns 1 connecting through the tunnel.
So at a first read, the simplification given by pq_get_last_result() is broken: the results should be returned one by one in the normal loop going through PQisBusy(), PQconsumeInput(), and the polling machinery. It seems a chunky refactoring but as it is now I don't like pq_get_last_result() anymore :(
As one issue(https://github.com/psycopg/psycopg2/issues/781) has already been created for conn.poll() function hangs when executes COPY command in async mode. Similarly conn.poll() functions hangs when we run wrong query in async mode using sshtunnel v0.1.3.
Can someone please suggest what went wrong when used sshtunnel, or the pointers/reason where poll() method hangs.
I am using psycopg2 2.7.4 to connect to the PostgreSQL database server using asynchronoussupport. It is working absolutely fine. I have used sshtunnel v0.1.3 in pgAdmin4. When I connect the PostgreSQL database server using ssh tunnel and run the valid/correct query it works fine, but when I run any wrong query(invalid column of table) my application gets hang on conn.poll() function.