facebook / facebook/hhvm

[ Segmentation fault ] Using `SQL\Query->toString__FOR_DEBUGGING_ONLY()` causes a segmentation fault when a query is also running

Open
#8,678 0 comments 0 reactions 0 assignees View on GitHub
crash
Dominant language
C++
Stars
18.7k
Forks
3.1k
Avg merge
1h 47m
Merged PRs (30d)
2

Description

**Describe the bug**

A segmentation fault occurs when running when asking for the string repr of a `SQL\Query` while the connection is busy.

**Standalone code, or other way to reproduce the problem**

```HACK
>
async function main_async(): Awaitable {
require_once __DIR__.'/../vendor/autoload.hack';
\Facebook\AutoloadMap\initialize();

$config = /*my config*/;

$async_conn = await AsyncMysqlClient::connect($config->servername, 3306, $config->dbname, $config->username, $config->password);

concurrent {
await func_async($async_conn, new SQL\Query('SELECT %s', 'something'));
await func_async($async_conn, new SQL\Query('SELECT %s', 'something'));
}
}

async function func_async(AsyncMysqlConnection $asyncMysql, SQL\Query $query): Awaitable {
$query->toString__FOR_DEBUGGING_ONLY($asyncMysql);
await $asyncMysql->queryf('SELECT %s', 'something');
}
```

Steps to reproduce the behavior:

Have a SQL server running.
I used `10.4.11-MariaDB-1:10.4.11+maria~bionic-log`.
Run the example code above.
Read stacktrace from /tmp/stacktrace.xxxxx.log

**Expected behavior**
Code completes silently.

**Screenshots**
`NONE`

**Desktop (please complete the following information):**
- OS: Ubuntu 18.04.4 LTS
- HHVM Version: 4.51.0

```
HipHop VM 4.51.0-dev (rel)
Compiler: 1585280615_594927537
Repo schema: ac933c8afa79ac54d3ec9e7de7983d3b2a7977f5
```

**Additional context**
Stacktrace
```
Host: lexidor-Cloud-VM
ProcessID: 27372
ThreadID: 140689418532416
ThreadPID: 27372
Name: /usr/bin/hhvm
CmdLine: hhvm library/autoload.php
Type: Segmentation fault
Runtime: hhvm
Version: 1585280615_594927537
DebuggerCount: 0

Arguments: library/autoload.php
ThreadType: CLI

# 0 000055811f319ee6
# 1 000055811f5e2a95
# 2 00007ff4cccaf890
# 3 00005581204c9fe5
# 4 0000558129214953
# 5 000055812921489b
# 6 0000558129215018
# 7 0000558125600491
# 8 000055811fc0b703
# 9 000055811f5fed22
# 10 000055812049cb96
# 11 00005581204af8b8
# 12 00005581204a9eab
# 13 0000558129200631
# 14 000055812920055d
# 15 0000558125600491
# 16 000055811fc0b703
# 17 000055811f978ae0
# 18 000055811f602dd6
# 19 0000558121296861
# 20 0000558121296688
# 21 00005581212963d0
# 22 000055811f684622
# 23 000055811f6855f2
# 24 000055811f68e3e5
# 25 000055811f6901ce
# 26 000055811f2a0974
# 27 00007ff4c61ccb97
# 28 000055811f29dc2a

PHP Stacktrace:

#0 HH\Lib\SQL\Query->toString__FOR_DEBUGGING_ONLY() called at [autoload.php:21]
#1 func_async() called at [autoload.php:16]
#2 main_async()
#3 Closure$__SystemLib\enter_async_entry_point()
#4 HH\Asio\join()
#5 __SystemLib\enter_async_entry_point()
```

Contributor guide

Open the contributing guide

Research direction

Start by running the standalone Hack example in autoload.php and inspect the calls to SQL\Query->toString__FOR_DEBUGGING_ONLY(), AsyncMysqlClient::connect(), and queryf() while the connection is busy. Use the supplied stack trace to locate the HHVM or SQL implementation involved; done means the concurrent example completes silently without a segmentation fault.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, mysql, sql
Domain
backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.