Chunked answer but hanging connection on graceful shutdown
- Dominant language
- C++
- Stars
- 18.7k
- Forks
- 3.1k
- Avg merge
- 1h 47m
- Merged PRs (30d)
- 2
Description
### HHVM Version
`hhvm --version`
```
HipHop VM 3.13.1 (rel)
Compiler: tags/HHVM-3.13.1-0-g4f382ad928a6e2a0607a8dcb251002aca77f11f6
Repo schema: 655b5912cb8136e9df6f9be972153e38ac446e0f
```
`uname -a`
```
Linux hostname 4.5.0-0.bpo.2-amd64 #1 SMP Debian 4.5.3-2~bpo8+1 (2016-05-13) x86_64 GNU/Linux
```
`lsb_release -a`
```
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 8.4 (jessie)
Release: 8.4
Codename: jessie
```
### Standalone code, or other way to reproduce the problem
`server.ini`
```
hhvm.server.type = fastcgi
```
`sleep.php`
```
echo "0\n"; sleep(1); flush();
echo "1\n"; sleep(1);
echo "2\n"; sleep(1);
echo "3\n"; sleep(1);
echo "4\n"; sleep(1);
echo "5 DONE\n";
```
Run script `sleep.php`.
Shortly after, in another shell, run `service hhvm stop`.
(You can as well call `localhost:9001/stop` on the admin port using the `cgi-fcgi` tool.)
### Expected result
```
0
1
2
3
4
5
```
### Actual result
```
0
1
```
### Issue description
As soon as I run `service hhvm stop`, the output stops, and after 4-5 seconds as the script got enough time to finish, the connection gets closed, and `service hhvm stop` returns.
The init script uses `start-stop-daemon --stop --quiet --retry=TERM/10/KILL/5 --pidfile $PIDFILE --name $NAME`, so it sends a `SIGTERM` and after 10 seconds it sends a `SIGKILL`, so the above script has enough time to finish.
The output stops as soon as hhvm receives the `SIGTERM` but the connection is held until the script finishes properly.
I would have expected the output to continue normally until the script finished (or the 10 seconds timeout trips), or at least the connection to be closed right away as no further output is being sent anyway (but I believe that behavior would qualify as a bug too).
### Workaround
`/etc/hhvm/server.ini`
```
hhvm.server.graceful_shutdown_wait = 10
```
With that option, the output continues normally, one line every second.
(If the script takes more than 10 seconds it is harshly killed as expected and the output stops then, because the connection is closed.)
### Behavior on older version
`hhvm --version`
```
HipHop VM 3.4.0 (rel)
Compiler: tags/HHVM-3.4.0-0-g817b3a07fc4e509ce15635dbc87778e5b3496663
Repo schema: 0e12aaa31fae66b5591f65603de50c9d62caafac
Extension API: 20140829
```
`uname -a`
```
Linux hostname 3.2.0-4-amd64 #1 SMP Debian 3.2.78-1 x86_64 GNU/Linux
```
`lsb_release -a`
```
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 7.10 (wheezy)
Release: 7.10
Codename: wheezy
```
In order to do a graceful shutdown with this version, instead of sending SIGTERM, I call `localhost:9001/stop` on the admin port using the `cgi-fcgi` tool.
On this older OS and HHVM versions I have a slightly different behavior.
The output is held until the script ends, at which point I get the expected output and the connection closes altogether.
The behavior with the workaround is the same as with the newer configuration.
### Hint
Looking at the behavior on the older versions, I think it might be related to the output being buffered.
Contributor guide
Assessment
This issue has not been assessed yet.