Commit 0ca9e6e
committed
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 #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.
Fixes #86781 parent 951787c commit 0ca9e6e
1 file changed
+13
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
326 | 326 | | |
327 | 327 | | |
328 | 328 | | |
329 | | - | |
330 | | - | |
331 | | - | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
332 | 334 | | |
333 | 335 | | |
334 | 336 | | |
| |||
1244 | 1246 | | |
1245 | 1247 | | |
1246 | 1248 | | |
| 1249 | + | |
| 1250 | + | |
1247 | 1251 | | |
1248 | 1252 | | |
1249 | 1253 | | |
| |||
1254 | 1258 | | |
1255 | 1259 | | |
1256 | 1260 | | |
| 1261 | + | |
| 1262 | + | |
1257 | 1263 | | |
1258 | 1264 | | |
1259 | 1265 | | |
| |||
1266 | 1272 | | |
1267 | 1273 | | |
1268 | 1274 | | |
| 1275 | + | |
| 1276 | + | |
1269 | 1277 | | |
1270 | 1278 | | |
1271 | 1279 | | |
| |||
1278 | 1286 | | |
1279 | 1287 | | |
1280 | 1288 | | |
| 1289 | + | |
| 1290 | + | |
1281 | 1291 | | |
1282 | 1292 | | |
1283 | 1293 | | |
| |||
0 commit comments