public inbox for [email protected]  
help / color / mirror / Atom feed
From: Sasmit Utkarsh <[email protected]>
To: pgsql-general <[email protected]>
To: [email protected]
Subject: Assistance Required: Timeout or Buffer Overflow Issue in PostgreSQL Client Application
Date: Thu, 24 Oct 2024 21:42:19 +0530
Message-ID: <CAM-5MT0B3RUXdWmzeK4DYF_igUKqViYS22pQoMr7pANrLHDVKg@mail.gmail.com> (raw)

Dear PostgreSQL Community Team,

I hope this message finds you well. I am reaching out for assistance with
an issue encountered in our application, which communicates with PostgreSQL
using the libpq client library.

*Issue Details:*
We have observed a problem where one of the application's threads gets
stuck during a database operation. Below is a stack trace of the affected
thread:

*Application Logs:*
Oct 23 10:08:44.806235 cucmtpccu1 [email protected][966034]:
0966070{ef5f81a7-d35b-4604-953d-a35665e505b7.010000}KIP8-SQL_get_tpf_rw()-SQL
read data from File Address before lock fa(-1810606079) fa(94145801) fa2
htonl(22549652)
Oct 23 10:08:44.806235 cucmtpccu1 [email protected][966034]:
0966070{ef5f81a7-d35b-4604-953d-a35665e505b7.010000}KIP8-SQL_get_tpf_rw()
SelectDataCommand = CALL SQL_select_data_procedure($1, $2, NULL, NULL)
hold(0) fa(-1810606079)
Oct 23 10:08:44.807814 cucmtpccu1 [email protected][966034]: *** buffer
overflow detected ***: terminated

*Stack Trace of Thread 966070:*
#0  0x00000000f7ee1129 __kernel_vsyscall (linux-gate.so.1)
#1  0x00000000f6ba23b7 __poll (libc.so.6)
#2  0x00000000f792e5b5 __interceptor_poll (libasan.so.8)
#3  0x00000000f72b30a8 pqSocketCheck (libpq.so.5)
#4  0x00000000f72b3864 pqWaitTimed (libpq.so.5)
#5  0x00000000f72b38d2 pqWait (libpq.so.5)
#6  0x00000000f72aff03 PQgetResult (libpq.so.5)
#7  0x00000000f72b036a PQexecFinish (libpq.so.5)
#8  0x0000000008106dd4 checkLOCK (server)
#9  0x000000000811d871 SQL_get_tpf_rw (server)
...

The stack trace shows that the thread is stuck in a poll operation while
waiting for socket activity within the PostgreSQL client library (libpq).
We suspect this could be related to a network timeout or issue. However,
the application logs indicate a buffer overflow before the crash, which
raises questions about whether these are related.

*Questions:*
-Could the buffer overflow be causing the crash, and if so, how is it
related to the socket activity?
-Are there specific configurations or checks we should perform to diagnose
this issue further?
-Any suggestions for possible solutions to resolve this problem?

For additional context, I've verified that the specified record does exist
in the database, and I am also attaching the implementation details for the
*checkLOCK* function corresponding to the stack trace.

Please let me know if you need any more details

Your assistance with troubleshooting this would be highly appreciated.

Regards,
Sasmit Utkarsh
+91-7674022625

void checkLOCK(int32_t fa)
{
int         nFields;
int         nTuples;
int         i, j;
PGresult *checkLOCK_res=NULL;
char Command[100];

	LOG_TRACE("%s() fa(%i)(%08X)",__func__,fa,fa);
        
	snprintf(Command,sizeof(Command),"SELECT pid, classid, objid FROM pg_locks WHERE objid=%i",fa);
        //PQclear(checkLOCK_res);
	checkLOCK_res = PQexec(conn,Command);

        if (!checkLOCK_res) {
           LOG_DEBUG("In %s(): PGresult is still NULL so return", __func__);
           return;
        }

        if (PQresultStatus(checkLOCK_res) != PGRES_TUPLES_OK) {
           LOG_DEBUG("checkLOCK failed: %s", PQerrorMessage(conn));
           PQclear(checkLOCK_res);
           return;
        }

        nFields = PQnfields(checkLOCK_res);
        nTuples = PQntuples(checkLOCK_res);

	if(nTuples > 0)
	{
		LOG_DEBUG("%s() fa(%i)(%08X) is currently LOCKED by PID %s as classid=%s objid=%s",__func__,fa,fa,PQgetvalue(checkLOCK_res,0,0),PQgetvalue(checkLOCK_res,0,1),PQgetvalue(checkLOCK_res,0,2));
        	PQclear(checkLOCK_res);
		//printLOCKS();
	}
	else
	{
		LOG_DEBUG("%s() fa(%i)(%08X) is NOT LOCKED",__func__,fa,fa);
        	PQclear(checkLOCK_res);
	}

}

Attachments:

  [text/plain] checkLOCK.txt (1.2K, 3-checkLOCK.txt)
  download | inline:
void checkLOCK(int32_t fa)
{
int         nFields;
int         nTuples;
int         i, j;
PGresult *checkLOCK_res=NULL;
char Command[100];

	LOG_TRACE("%s() fa(%i)(%08X)",__func__,fa,fa);
        
	snprintf(Command,sizeof(Command),"SELECT pid, classid, objid FROM pg_locks WHERE objid=%i",fa);
        //PQclear(checkLOCK_res);
	checkLOCK_res = PQexec(conn,Command);

        if (!checkLOCK_res) {
           LOG_DEBUG("In %s(): PGresult is still NULL so return", __func__);
           return;
        }

        if (PQresultStatus(checkLOCK_res) != PGRES_TUPLES_OK) {
           LOG_DEBUG("checkLOCK failed: %s", PQerrorMessage(conn));
           PQclear(checkLOCK_res);
           return;
        }

        nFields = PQnfields(checkLOCK_res);
        nTuples = PQntuples(checkLOCK_res);

	if(nTuples > 0)
	{
		LOG_DEBUG("%s() fa(%i)(%08X) is currently LOCKED by PID %s as classid=%s objid=%s",__func__,fa,fa,PQgetvalue(checkLOCK_res,0,0),PQgetvalue(checkLOCK_res,0,1),PQgetvalue(checkLOCK_res,0,2));
        	PQclear(checkLOCK_res);
		//printLOCKS();
	}
	else
	{
		LOG_DEBUG("%s() fa(%i)(%08X) is NOT LOCKED",__func__,fa,fa);
        	PQclear(checkLOCK_res);
	}

}

view thread (3+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: Assistance Required: Timeout or Buffer Overflow Issue in PostgreSQL Client Application
  In-Reply-To: <CAM-5MT0B3RUXdWmzeK4DYF_igUKqViYS22pQoMr7pANrLHDVKg@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox