Swoole-src: Random bytes added to response status code

Created on 26 Sep 2019  ·  14Comments  ·  Source: swoole/swoole-src

Please answer these questions before submitting your issue. Thanks!

  1. What did you do? If possible, provide a simple script for reproducing the error.
  • Our setup is:
    * Swoole 4.4.7 with Slim v4
    *
    rdkafka 3.1.2 installed
  1. What did you expect to see?
  • I make a request and get a "regular" response
  1. What did you see instead?
  • I make a request and get the regular response plus a couple of bytes added to the status code:
HTTP/1.1 200 OKj�
  1. What version of Swoole are you using (show your php --ri swoole)?
swoole

Swoole => enabled
Author => Swoole Team <[email protected]>
Version => 4.4.7
Built => Sep 25 2019 14:32:39
coroutine => enabled
epoll => enabled
eventfd => enabled
signalfd => enabled
spinlock => enabled
rwlock => enabled
http2 => enabled
zlib => enabled
mutex_timedlock => enabled
pthread_barrier => enabled
async_redis => enabled

Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => On => On
swoole.unixsock_buffer_size => 8388608 => 8388608
  1. What is your machine environment used (including version of kernel & php & gcc) ?
  • Docker container
  • PHP:
PHP 7.3.9 (cli) (built: Sep  3 2019 06:40:35) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.9, Copyright (c) 1998-2018 Zend Technologies
  • gcc:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-alpine-linux-musl/8.3.0/lto-wrapper
Target: x86_64-alpine-linux-musl
Configured with: /home/buildozer/aports/main/gcc/src/gcc-8.3.0/configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --build=x86_64-alpine-linux-musl --host=x86_64-alpine-linux-musl --target=x86_64-alpine-linux-musl --with-pkgversion='Alpine 8.3.0' --enable-checking=release --disable-fixed-point --disable-libstdcxx-pch --disable-multilib --disable-nls --disable-werror --disable-symvers --enable-__cxa_atexit --enable-default-pie --enable-default-ssp --enable-cloog-backend --enable-languages=c,c++,objc,fortran,ada --disable-libssp --disable-libmpx --disable-libmudflap --disable-libsanitizer --enable-shared --enable-threads --enable-tls --with-system-zlib --with-linker-hash-style=gnu
Thread model: posix
gcc version 8.3.0 (Alpine 8.3.0) 
  • Kernel: 4.15.0-64-generic

Additions:

  • We replaced swoole with ReactPHP and the problem was resolved. That is why we think it is releated to swoole itself.
  • Killing the process (die()) causes the next request to not have those random bytes
  • The bytes are always the same UNTIL the process dies
bug fixed

Most helpful comment

Swoole 4.4.8 was released early today.

All 14 comments

If it is compiled from source, are you make clean before upgrading?

How can I reproduce this problem?

No, the extension is installed via pecl. About the reproduction ... to be honest, I have no clue. We have one other swoole project that is not suffering from that problem. I'll figure something out and get back to you

run your application in the following way:

USE_ZEND_ALLOC=0 valgrind --log-file=/tmp/valgrind.log php xxx.php

and show your log here

maybe we can trace some memory errors

@twose this can be reproduced here:
https://github.com/nick-zh/swoole-debug

It is a small hello world project using Slim 4 and the https://github.com/chubbyphp/chubbyphp-swoole-request-handler to transform the requests.

I am not familiar with valgrind, as soon as i change the startup to use valgrind:
https://github.com/nick-zh/swoole-debug/blob/master/docker/php/files/startup.sh#L5
(so uncomment L5 and comment L6)
The random bytes disappear (but maybe this is normal, i don't know)
Let me know if you need more information

Thanks @nick-zh! I will then wait with the log file. This is surely more helpful :)

The problem may be triggered by explicitly setting a reason phrase on the swool response in the response emitter. If I remove the custom reason I just get a correct reason without any random bytes: https://github.com/chubbyphp/chubbyphp-swoole-request-handler/blob/master/src/SwooleResponseEmitter.php#L16

Edit: Doing the following also prevents random bytes:

$swooleResponse->status($response->getStatusCode(), $response->getReasonPhrase() . "\x00");

@nick-zh
Although the random bytes disappeared, it doesn't mean the memory error didn't happen
So I still need to check your log for more information

A stupid mistake
Fixed in master

Thank you! :)

@twose awesome, thank you very much!

@twose would be cool if you could do a bugfix release with that fix

@dominikzogg It's Golden Week in China. Most team members are taking a break and won't be available until Oct 8th. Once back from the break, they will schedule a new release for the 4.4 series.

Swoole 4.4.8 was released early today.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jobs-git picture jobs-git  ·  3Comments

lotarbo picture lotarbo  ·  4Comments

sshymko picture sshymko  ·  3Comments

qifengzhang007 picture qifengzhang007  ·  3Comments

pthreat picture pthreat  ·  3Comments