Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Http2 protocol not handled correctly, and not recognize libnghttp2.so by ffi. #12

Closed
xpader opened this issue Jul 31, 2023 · 12 comments
Closed
Labels
bug Something isn't working

Comments

@xpader
Copy link

xpader commented Jul 31, 2023

Version amphp/http-client 4.6.2.
PHP Version: 8.0, 8.1

Some request from out linux server (Ubuntu 20.04) always return Amp\Http\Client\Connection\Http2ConnectionException: The HTTP/2 connection from '192.168.1.112:41306' to '****:443' closed, but from local develop machine (MacOS 13.4) always success.

After some dig, I found that reason is local machine can correct locate libnghttp2.dylib to use HPackNgHttp2, but server can't locate libnghttp2.so.

By apt, I found that libnghttp2 package is libnghttp2-14 in server, and files list:

dpkg -L libnghttp2-14
/.
/usr
/usr/lib
/usr/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu/libnghttp2.so.14.19.0
/usr/share
/usr/share/doc
/usr/share/doc/libnghttp2-14
/usr/share/doc/libnghttp2-14/AUTHORS
/usr/share/doc/libnghttp2-14/README.rst.gz
/usr/share/doc/libnghttp2-14/changelog.Debian.gz
/usr/share/doc/libnghttp2-14/copyright
/usr/lib/x86_64-linux-gnu/libnghttp2.so.14
/.
/usr
/usr/lib
/usr/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu/libnghttp2.so.14.19.0
/usr/share
/usr/share/doc
/usr/share/doc/libnghttp2-14
/usr/share/doc/libnghttp2-14/AUTHORS
/usr/share/doc/libnghttp2-14/README.rst.gz
/usr/share/doc/libnghttp2-14/changelog.Debian.gz
/usr/share/doc/libnghttp2-14/copyright
/usr/lib/x86_64-linux-gnu/libnghttp2.so.14

There is no libnghttp2.so file in server, only libnghttp2.so.14, when I change libnghttp2.so to libnghttp2.so.14 in here:

self::$ffi = FFI::cdef($header, 'libnghttp2.so');

It's worked.

There's two problem here:

  • HPackNative not correctly handle http2 protocol, makes HTTP/2 connection closed error.
  • FFI can not locate the right libnghttp2.so.* file, fallback to HPackNative.

GPT give me a answer that we can create a symbol link to real libnghttp2.so.* file or use ldconfig -p | grep 'libnghttp2.so' | awk '{print $4}' to locate it.

@kelunik kelunik added the bug Something isn't working label Jul 31, 2023
@kelunik
Copy link
Member

kelunik commented Jul 31, 2023

@xpader It'd be great to get a binary dump of the received / sent bytes to find the bug in our HPackNative implementation. Note that sharing these headers could contain sensitive values.

Which OS / distro do you use that has these paths?

@xpader
Copy link
Author

xpader commented Aug 1, 2023

@kelunik OS is Ubuntu 20.04.5 LTS x64, and how to get a binary dump with received / sent bytes?

@xpader
Copy link
Author

xpader commented Aug 1, 2023

After change to HPackNgHttp2, some error appeared: Cannot instantiate FFI\CData of zero size.
Tough..

@kelunik
Copy link
Member

kelunik commented Aug 1, 2023

@xpader don't worry about the binary dump, I did some fuzzing yesterday and discovered several strange cases I need to investigate further.

@kelunik kelunik transferred this issue from amphp/http-client Aug 5, 2023
@trowski
Copy link
Member

trowski commented Aug 11, 2023

I fixed the Cannot instantiate FFI\CData of zero size issue in the current branch. I'll tag a bugfix release for that change while we find some time to investigate the other issue.

@xpader
Copy link
Author

xpader commented Aug 14, 2023

I have a http request example to reproducer this error (still exists in version 3.1.3), but the example include some sensitive infomation, how could I send this to you?

@xpader
Copy link
Author

xpader commented Aug 17, 2023

FFI memory leak very exaggerated, and memory is leak outer of PHP memory manager.
The memory info from memory_get_usage() is very normal, but in system, php process memory is now 4G after running 2 days. Even set memory_limit for php, process still not exit after memory exceed.

@kelunik
Copy link
Member

kelunik commented Aug 17, 2023

You can send it to me@kelunik.com.

@xpader
Copy link
Author

xpader commented Sep 1, 2023

Mail has been sent to you, any updates?

@kelunik
Copy link
Member

kelunik commented Sep 4, 2023

@xpader Do you use the proxy-authenticate header?

@xpader
Copy link
Author

xpader commented Sep 5, 2023

@kelunik No.
Did you received the mail? I have sent the simple request example can reproduce this issue.

@kelunik kelunik closed this as completed in 06e8d74 Sep 5, 2023
@kelunik
Copy link
Member

kelunik commented Sep 5, 2023

@xpader Yes, I received it, I should have had another look at it before writing that comment. Anyway, I could reproduce the issue and have fixed it now. Thanks for reporting!

kelunik added a commit that referenced this issue Sep 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

3 participants