Merge pull request #116 from WebFreak001/fix-115
release ref on failing connectTCP
This commit is contained in:
commit
568cdb112b
|
@ -215,7 +215,16 @@ TCPConnection connectTCP(NetworkAddress addr, NetworkAddress bind_address = anyA
|
||||||
|
|
||||||
enforce(!cancelled, "Failed to connect to " ~ addr.toString() ~
|
enforce(!cancelled, "Failed to connect to " ~ addr.toString() ~
|
||||||
": timeout");
|
": timeout");
|
||||||
enforce(status == ConnectStatus.connected, "Failed to connect to "~addr.toString()~": "~status.to!string);
|
|
||||||
|
if (status != ConnectStatus.connected) {
|
||||||
|
if (sock != SocketFD.invalid) {
|
||||||
|
bool refsLeft = eventDriver.sockets.releaseRef(sock);
|
||||||
|
assert(!refsLeft);
|
||||||
|
}
|
||||||
|
|
||||||
|
enforce(false, "Failed to connect to "~addr.toString()~": "~status.to!string);
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
|
||||||
return TCPConnection(sock, uaddr);
|
return TCPConnection(sock, uaddr);
|
||||||
} ();
|
} ();
|
||||||
|
|
22
tests/issue-115-connect-fail-leak.d
Normal file
22
tests/issue-115-connect-fail-leak.d
Normal 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) { }
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue