Skip to content

Commit

Permalink
When an attempt to open a unix sucket failed, the socket was not prop…
Browse files Browse the repository at this point in the history
…erly closed.
  • Loading branch information
9EOR9 committed Sep 24, 2016
1 parent 878f143 commit c8dd089
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions plugins/pvio/pvio_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -772,10 +772,12 @@ my_bool pvio_socket_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo)
{
PVIO_SET_ERROR(cinfo->mysql, CR_CONNECTION_ERROR, SQLSTATE_UNKNOWN,
ER(CR_CONNECTION_ERROR), cinfo->unix_socket, socket_errno);
closesocket(csock->socket);
goto error;
}
if (pvio_socket_blocking(pvio, 1, 0) == SOCKET_ERROR)
{
closesocket(csock->socket);
goto error;
}
#else
Expand Down
29 changes: 29 additions & 0 deletions unittest/libmariadb/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,36 @@ static int test_sess_track_db(MYSQL *mysql)
return OK;
}

static int test_unix_socket_close(MYSQL *unused __attribute__((unused)))
{
MYSQL *mysql= mysql_init(NULL);
FILE *fp;
int i;

if (!(fp= fopen("./dummy_sock", "w")))
{
diag("couldn't create dummy socket");
return FAIL;
}
fclose(fp);

for (i=0; i < 10000; i++)
{
mysql_real_connect(mysql, "localhost", "user", "passwd", NULL, 0, "./dummy_sock", 0);
/* check if we run out of sockets */
if (mysql_errno(mysql) == 2001)
{
diag("out of sockets after %d attempts", i);
mysql_close(mysql);
return FAIL;
}
}
mysql_close(mysql);
return OK;
}

struct my_tests_st my_tests[] = {
{"test_unix_socket_close", test_unix_socket_close, TEST_CONNECTION_NONE, 0, NULL, NULL},
{"test_sess_track_db", test_sess_track_db, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_get_options", test_get_options, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_wrong_bind_address", test_wrong_bind_address, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
Expand Down

0 comments on commit c8dd089

Please sign in to comment.