You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Consistently check connection validity in AsyncMysqlConnection
The Squangle connection pointer wrapped by AsyncMysqlConnection may be
nullptr if the connection was closed or is currently busy waiting for
the result of an async query. Most code paths already call either
verifyValidConnection() to raise an appropriate Hack exception or
explicitly check for and handle a null backing connection, but
Query::toString__FOR_DEBUGGING_ONLY() and the SSL-related getters from
D33663743 do not, which can lead to segfaults.
Slightly simplified reproducer from facebook#8678:
```hack
use namespace HH\Lib\SQL;
<<__EntryPoint>>
async function main_async(): Awaitable<void> {
// connection parameters as needed
$async_conn = await AsyncMysqlClient::connect('127.0.0.1', 3306, 'foo', 'root', 'pass');
$async_conn->close();
var_dump($async_conn->getSslCertCn());
}
async function func_async(AsyncMysqlConnection $asyncMysql, SQL\Query $query): Awaitable<void> {
$query->toString__FOR_DEBUGGING_ONLY($asyncMysql);
var_dump($asyncMysql->getSslCertCn());
await $asyncMysql->queryf('SELECT %s', 'something');
}
```
and for `(get|is)Ssl.*`:
```hack
use namespace HH\Lib\SQL;
<<__EntryPoint>>
async function main_async(): Awaitable<void> {
$async_conn = await AsyncMysqlClient::connect('127.0.0.1', 3306, 'foo', 'root', 'wikia123456');
$async_conn->close();
var_dump($async_conn->getSslCertCn());
}
```
Call verifyValidConnection() in all these cases, as raising an
appropriate exception (e.g. closed/busy connection) seems appropriate
here.
Fixesfacebook#8678
0 commit comments