diff --git a/include/znc/Socket.h b/include/znc/Socket.h index 34bedf87..e0e0ab7a 100644 --- a/include/znc/Socket.h +++ b/include/znc/Socket.h @@ -155,12 +155,15 @@ class CSockManager : public TSocketManager { const CString& sBindHost = "", CZNCSock* pcSock = nullptr); unsigned int GetAnonConnectionCount(const CString& sIP) const; + void DelSockByAddr(Csock* pcSock) override; private: void FinishConnect(const CString& sHostname, u_short iPort, const CString& sSockName, int iTimeout, bool bSSL, const CString& sBindHost, CZNCSock* pcSock); + std::map m_InFlightDnsSockets; + #ifdef HAVE_PTHREAD class CThreadMonitorFD; friend class CThreadMonitorFD; diff --git a/src/Socket.cpp b/src/Socket.cpp index dcf53b98..3a18f785 100644 --- a/src/Socket.cpp +++ b/src/Socket.cpp @@ -392,6 +392,7 @@ CSockManager::~CSockManager() {} void CSockManager::Connect(const CString& sHostname, u_short iPort, const CString& sSockName, int iTimeout, bool bSSL, const CString& sBindHost, CZNCSock* pcSock) { + m_InFlightDnsSockets[pcSock] = false; if (pcSock) { pcSock->SetHostToVerifySSL(sHostname); } @@ -423,6 +424,20 @@ void CSockManager::FinishConnect(const CString& sHostname, u_short iPort, const CString& sSockName, int iTimeout, bool bSSL, const CString& sBindHost, CZNCSock* pcSock) { + auto it = m_InFlightDnsSockets.find(pcSock); + if (it != m_InFlightDnsSockets.end()) { + bool bSocketDeletedAlready = it->second; + m_InFlightDnsSockets.erase(it); + if (bSocketDeletedAlready) { + DEBUG("TDNS: Socket [" + << sSockName + << "] is deleted already, not proceeding with connection"); + return; + } + } else { + // impossible + } + CSConnection C(sHostname, iPort, iTimeout); C.SetSockName(sSockName); @@ -439,6 +454,16 @@ void CSockManager::FinishConnect(const CString& sHostname, u_short iPort, TSocketManager::Connect(C, pcSock); } +void CSockManager::DelSockByAddr(Csock* pcSock) { + auto it = m_InFlightDnsSockets.find(pcSock); + if (it != m_InFlightDnsSockets.end()) { + // The socket is resolving its DNS. When that finishes, let it silently + // die without crash. + it->second = true; + } + TSocketManager::DelSockByAddr(pcSock); +} + /////////////////// CSocket /////////////////// CSocket::CSocket(CModule* pModule) : CZNCSock(), m_pModule(pModule) { if (m_pModule) m_pModule->AddSocket(this); diff --git a/version.sh b/version.sh index 9b8daeba..339bfe5a 100755 --- a/version.sh +++ b/version.sh @@ -16,7 +16,7 @@ else # Figure out the information we need LATEST_TAG=`${GIT} describe --abbrev=0 HEAD` - COMMITS_SINCE=`${GIT} log --format=oneline ${LATEST_TAG}..HEAD | wc -l` + COMMITS_SINCE=`${GIT} log --pretty=oneline ${LATEST_TAG}..HEAD | wc -l` # Explicitly make it a number: on openbsd wc -l returns " 42" instead of "42" let COMMITS_SINCE=COMMITS_SINCE SHORT_ID=`${GIT} rev-parse --short HEAD`