-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Consider this trivial snippet with a Tarantool instance listening on port 3301
:
#include "../src/Client/Connector.hpp"
using Buf_t = tnt::Buffer<16 * 1024>;
using Net_t = LibevNetProvider<Buf_t, DefaultStream>;
int
main()
{
Connector<Buf_t, Net_t> client;
Connection<Buf_t, Net_t> conn(client);
struct ConnectOptions conn_opts{
.address = "127.0.0.1",
.service = "3301",
};
printf("%d", client.connect(conn, conn_opts));
conn.ping(); /* Tarantool server dies causing the connection to be set to dead state. */
printf("%d", client.connect(conn, conn_opts);
}
Both connect
s succeed, because the Connector
and NetProvider
s relies only on the stream status to determine whether a connection is established:
tntcxx/src/Client/Connector.hpp
Lines 142 to 147 in 8e009e8
int | |
Connector<BUFFER, NetProvider>::connect(Connection<BUFFER, NetProvider> &conn, | |
const ConnectOptions &opts) | |
{ | |
//Make sure that connection is not yet established. | |
assert(conn.get_strm().has_status(SS_DEAD)); |
tntcxx/src/Client/UnixStream.hpp
Lines 157 to 161 in 8e009e8
inline int | |
UnixStream::connect(const ConnectOptions &opts_arg) | |
{ | |
if (!has_status(SS_DEAD)) | |
return US_DIE("Double connect"); |
This leads to leak of the previous socket, since it does not get closed by the connect code
:
tntcxx/src/Client/UnixStream.hpp
Lines 157 to 171 in 8e009e8
inline int | |
UnixStream::connect(const ConnectOptions &opts_arg) | |
{ | |
if (!has_status(SS_DEAD)) | |
return US_DIE("Double connect"); | |
opts = opts_arg; | |
AddrInfo addr_info(opts.address, opts.service); | |
if (addr_info.last_rc() != 0) | |
return US_DIE("Network address resolve failed", | |
addr_info.last_error()); | |
int socket_errno = 0, connect_errno = 0; | |
for (auto &inf: addr_info) { | |
fd = ::socket(inf.ai_family, inf.ai_socktype, inf.ai_protocol); |
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working