Skip to content

Destroy broken connection when it is put back to a pool #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Totktonada opened this issue Nov 22, 2019 · 2 comments
Closed

Destroy broken connection when it is put back to a pool #32

Totktonada opened this issue Nov 22, 2019 · 2 comments
Labels
bug Something isn't working

Comments

@Totktonada
Copy link
Member

The case: a connection is acquired from a pool, a request is made with this connection and fails, the connection is put back to the pool.

The connection is marked as broken in the case and will be discarded: a pool will not actually cache it, just count (<pool object>.queue:put(nil) under hood) that it may give (and create if needed) one more connection when it will be acquired. The math here looks correct. However an underlying raw connection of this 'broken' connection will not be closed neither when it put back to the pool, nor at GC (because the GC callback is removed at <pool object>:put() for both broken and healthy connections).

This behaviour looks as a bug. I propose to destroy the underlying connection when it is discarded at <pool object>:put(): i. e. close the underlying connection if it is broken.

We should test than the underlying connection is closed in the case.

@LeonidVas
Copy link
Contributor

Related: #46

@Totktonada
Copy link
Member Author

I overlooked the GC callback in driver.c (only looked over init.lua):

{"__gc", lua_mysql_gc},

mysql/mysql/driver.c

Lines 525 to 542 in 8301898

/**
* collect connection
*/
static int
lua_mysql_gc(struct lua_State *L)
{
struct mysql_connection **conn_p = (struct mysql_connection **)
luaL_checkudata(L, 1, mysql_driver_label);
if (conn_p != NULL && *conn_p != NULL && (*conn_p)->raw_conn != NULL) {
mysql_close((*conn_p)->raw_conn);
(*conn_p)->raw_conn = NULL;
}
if (conn_p != NULL && *conn_p != NULL) {
free(*conn_p);
*conn_p = NULL;
}
return 0;
}

So everything should be good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants