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

Http Server - SWOOLE_HOOK_TCP - stream_socket_enable_crypto() #4909

Open
smathersPersonal opened this issue Nov 17, 2022 · 5 comments
Open
Labels
in progress Maintainers are working on this

Comments

@smathersPersonal
Copy link

Hi there, Love the project. Ran into a bit of an issue and I'm stumped.

  • I'm using your http server which is behind nginx.
  • The problem is sending an email (Using PHPmailer) during an api call.
  • I have the server setup like this:
$server = new Swoole\HTTP\Server('[::]', 9009);
$cpus = swoole_cpu_num();
$server->set([
  'reactor_num' => $cpus * 2,
  'worker_num' => $cpus * 8,
  'task_enable_coroutine' => true,
  'hook_flags' => SWOOLE_HOOK_TCP | SWOOLE_HOOK_NATIVE_CURL | SWOOLE_HOOK_SLEEP | SWOOLE_HOOK_BLOCKING_FUNCTION,
  'dispatch_mode' => 1
]);
  • The reason for not using ALL hooks was because I'm not seeing great performance with it. I get the feeling its bouncing around between coroutines to much or something. Must be something with my application work flow, I do have lots of logging etc. I noticed not including this one makes a difference in speed: SWOOLE_HOOK_FILE
  • Sending an email I spawn another coroutine using the go() command to run it async, then I see this during smtp:
2022-11-17 04:35:42.969 >> Api d-ivr01 123151 [INFO ] SMTP: Connection: opening to email-smtp.us-east-1.amazonaws.com:25, timeout=300, options=[]
2022-11-17 04:35:42.969 >> Api d-ivr01 123151 [INFO ] Sending email: smathers@???????.com Subject: sdas
2022-11-17 04:35:42.972 >> Api d-ivr01 123151 [INFO ] SMTP: Connection: opened
2022-11-17 04:35:42.974 >> Api d-ivr01 123151 [INFO ] SMTP: SMTP INBOUND: "220 email-smtp.amazonaws.com ESMTP SimpleEmailService-????????"
2022-11-17 04:35:42.974 >> Api d-ivr01 123151 [INFO ] SMTP: SERVER -> CLIENT: 220 email-smtp.amazonaws.com ESMTP SimpleEmailService-????????
2022-11-17 04:35:42.974 >> Api d-ivr01 123151 [INFO ]
2022-11-17 04:35:42.974 >> Api d-ivr01 123151 [INFO ] SMTP: CLIENT -> SERVER: EHLO d-ivr01
2022-11-17 04:35:42.974 >> Api d-ivr01 123151 [INFO ]
2022-11-17 04:35:42.975 >> Api d-ivr01 123151 [INFO ] SMTP: SMTP INBOUND: "250-email-smtp.amazonaws.com"
2022-11-17 04:35:42.975 >> Api d-ivr01 123151 [INFO ] SMTP: SMTP INBOUND: "250-8BITMIME"
2022-11-17 04:35:42.975 >> Api d-ivr01 123151 [INFO ] SMTP: SMTP INBOUND: "250-STARTTLS"
2022-11-17 04:35:42.975 >> Api d-ivr01 123151 [INFO ] SMTP: SMTP INBOUND: "250-AUTH PLAIN LOGIN"
2022-11-17 04:35:42.975 >> Api d-ivr01 123151 [INFO ] SMTP: SMTP INBOUND: "250 Ok"
2022-11-17 04:35:42.975 >> Api d-ivr01 123151 [INFO ] SMTP: SERVER -> CLIENT: 250-email-smtp.amazonaws.com
2022-11-17 04:35:42.975 >> Api d-ivr01 123151 [INFO ] 250-8BITMIME
2022-11-17 04:35:42.975 >> Api d-ivr01 123151 [INFO ] 250-STARTTLS
2022-11-17 04:35:42.975 >> Api d-ivr01 123151 [INFO ] 250-AUTH PLAIN LOGIN
2022-11-17 04:35:42.975 >> Api d-ivr01 123151 [INFO ] 250 Ok
2022-11-17 04:35:42.975 >> Api d-ivr01 123151 [INFO ]
2022-11-17 04:35:42.976 >> Api d-ivr01 123151 [INFO ] SMTP: CLIENT -> SERVER: STARTTLS
2022-11-17 04:35:42.976 >> Api d-ivr01 123151 [INFO ]
2022-11-17 04:35:42.977 >> Api d-ivr01 123151 [INFO ] SMTP: SMTP INBOUND: "220 Ready to start TLS"
2022-11-17 04:35:42.977 >> Api d-ivr01 123151 [INFO ] SMTP: SERVER -> CLIENT: 220 Ready to start TLS
2022-11-17 04:35:42.977 >> Api d-ivr01 123151 [INFO ]
2022-11-17 04:35:43.072 >> Api d-ivr01 123151 [INFO ] SMTP: CLIENT -> SERVER: QUIT
2022-11-17 04:35:43.072 >> Api d-ivr01 123151 [INFO ]
2022-11-17 04:35:43.074 >> Api d-ivr01 123151 [INFO ] SMTP: SMTP INBOUND: "221 Bye"
2022-11-17 04:35:43.074 >> Api d-ivr01 123151 [INFO ] SMTP: SERVER -> CLIENT: 221 Bye
2022-11-17 04:35:43.074 >> Api d-ivr01 123151 [INFO ]
2022-11-17 04:35:43.074 >> Api d-ivr01 123151 [INFO ] SMTP: Connection: closed
  • If I remove the hook: SWOOLE_HOOK_TCP, it works. Problem is though I want that hook for the mysqli!!
  • I looked through the the PHPmailer code and my best guess is there is an issue with stream_socket_enable_crypto and the streams hook or I've missed something.

Thanks!!

Server Info:

Swoole => enabled
Author => Swoole Team <team@swoole.com>
Version => 5.0.1-dev
Built => Nov 16 2022 22:29:32
coroutine => enabled with boost asm context
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
openssl => OpenSSL 1.1.1f  31 Mar 2020
dtls => enabled
http2 => enabled
json => enabled
pcre => enabled
zlib => 1.2.11
mutex_timedlock => enabled
pthread_barrier => enabled
futex => 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
Linux d-ivr01 5.15.0-1022-aws #26~20.04.1-Ubuntu SMP Sat Oct 15 03:23:19 UTC 2022 aarch64 aarch64 aarch64 GNU/Linux
PHP 8.0.3 (cli) (built: Jan 20 2022 03:43:11) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.3, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.3, Copyright (c), by Zend Technologies
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/aarch64-linux-gnu/9/lto-wrapper
Target: aarch64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.4.0-1ubuntu1~20.04.1' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=aarch64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libquadmath --disable-libquadmath-support --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --enable-fix-cortex-a53-843419 --disable-werror --enable-checking=release --build=aarch64-linux-gnu --host=aarch64-linux-gnu --target=aarch64-linux-gnu
Thread model: posix
gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
@Draghmar
Copy link

Draghmar commented Dec 6, 2022

I run into the same issue, also with SES. I was wandering if it's related to the Swoole and some hook. The only difference for me is using task for sending. But the smtp log looks exactly the same.

@matyhtf matyhtf added in progress Maintainers are working on this and removed waiting on review labels Feb 28, 2023
@matyhtf
Copy link
Member

matyhtf commented Feb 28, 2023

SMTP uses the startSSL feature to dynamically enable encryption. There may be some problems with swoole hook support here. I am working to fix it

@TorstenDittmann
Copy link
Sponsor

Running into the same issue 👍🏻

stnguyen90 added a commit to appwrite/appwrite that referenced this issue Apr 3, 2024
Due to a bug in the Swoole TCP hook, the worker crashes when doing the
TLS handshake. This PR disables the Swoole TCP hook just like we do
in the mails worker.

References:
* #7914
* #6966
* swoole/swoole-src#4909
@ging-dev
Copy link

Looking forward to this feature

@Draghmar
Copy link

@matyhtf Hey, do you think there's a chance to get this fixed? I'm asking because I suddenly got task to do where I will need to send e-mail from within api. Up until now I've manage to mitigate this by sending e-mail from different env. Now it won't be possible. So I'd love to be able to send this without have to find some quirk workaround. ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in progress Maintainers are working on this
Projects
None yet
Development

No branches or pull requests

5 participants