Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Close and delete the socket if connect() fails #57

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/Connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,9 @@ bool Connection::connect(const char *_host, int _port, const char *_username, co
if (!connectSocket())
{
m_dbgMethodProgress --;
m_capi.closeSocket(m_sockInst);
m_capi.deleteSocket(m_sockInst);
m_sockInst = NULL;
return false;
}

Expand Down
3 changes: 2 additions & 1 deletion tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def testConnectTimeout(self):
try:
res = cnn.query("select * from kaka");
assert False, "Expected exception"
except(socket.error):
except(RuntimeError):
pass
cnn.close()

Expand All @@ -161,6 +161,7 @@ def testConnectFails(self):
assert False, "Expected exception"
except(socket.error):
pass
self.assertFalse(cnn.is_connected())
cnn.close()

def testConnectDNSFails(self):
Expand Down