release ref on failing connectTCP

fix #115
This commit is contained in:
WebFreak001 2019-01-09 00:18:43 +01:00
parent ea4917d4d0
commit 9d6b34c73a
2 changed files with 30 additions and 1 deletions

View file

@ -216,7 +216,14 @@ TCPConnection connectTCP(NetworkAddress addr, NetworkAddress bind_address = anyA
enforce(!cancelled, "Failed to connect to " ~ addr.toString() ~
": timeout");
enforce(status == ConnectStatus.connected, "Failed to connect to "~addr.toString()~": "~status.to!string);
if (status != ConnectStatus.connected) {
if (sock != SocketFD.invalid)
assert(!eventDriver.sockets.releaseRef(sock));
enforce(false, "Failed to connect to "~addr.toString()~": "~status.to!string);
assert(false);
}
return TCPConnection(sock, uaddr);
} ();

View file

@ -0,0 +1,22 @@
/+ dub.sdl:
name "test"
dependency "vibe-core" path=".."
+/
module test;
import vibe.core.core;
import vibe.core.log;
import vibe.core.net;
void main()
{
foreach (_; 0 .. 20) {
TCPConnection conn;
try {
conn = connectTCP("127.0.0.1", 16565);
logError("Connection: %s", conn);
conn.close();
assert(false, "Didn't expect TCP connection on port 16565 to succeed");
} catch (Exception) { }
}
}