From b24a91181f58c7f7141de8995ff212993bcc333b Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Thu, 23 Apr 2020 13:24:26 +0100 Subject: Opt-out of pgsql read and write events if polling fails. --- src/modules/extra/m_pgsql.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/modules/extra/m_pgsql.cpp b/src/modules/extra/m_pgsql.cpp index c454befae..916f164d1 100644 --- a/src/modules/extra/m_pgsql.cpp +++ b/src/modules/extra/m_pgsql.cpp @@ -57,6 +57,9 @@ typedef insp::flat_map ConnMap; enum SQLstatus { + // The connection has died. + DEAD, + // Connecting and wants read event. CREAD, @@ -310,6 +313,8 @@ class SQLConn : public SQL::Provider, public EventHandler status = CREAD; return true; case PGRES_POLLING_FAILED: + SocketEngine::ChangeEventMask(this, FD_WANT_NO_READ | FD_WANT_NO_WRITE); + status = DEAD; return false; case PGRES_POLLING_OK: SocketEngine::ChangeEventMask(this, FD_WANT_POLL_READ | FD_WANT_NO_WRITE); @@ -399,7 +404,7 @@ restart: { DoPoll(); } - else + else if (status == WREAD || status == WWRITE) { DoConnectedPoll(); } @@ -500,6 +505,7 @@ restart: void Close() { + status = DEAD; SocketEngine::DelFd(this); if(sql) @@ -612,6 +618,7 @@ bool ReconnectTimer::Tick(time_t time) void SQLConn::DelayReconnect() { + status = DEAD; ModulePgSQL* mod = (ModulePgSQL*)(Module*)creator; ConnMap::iterator it = mod->connections.find(conf->getString("id")); if (it != mod->connections.end()) -- cgit v1.2.3