-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Description
Summary
This error found from our rust-wrapper of mbedtls, Ref: fortanix/rust-mbedtls#301
TLS 1.3 connection is unstable(sometimes break) in multi-thread env:
- run server in one thread/process
- spawn multiple thread/process of client to connect server continuously
- Then. sometimes the TLS connection will break, the error is random
System information
Mbed TLS version (number or commit id): 17526a0d168276aa3ba5833cbb1f8fcd69d688ba
Operating system and version: Linux yuxiangcao-ThinkPad-T14-Gen-1 5.15.0-79-generic #86~20.04.2-Ubuntu SMP Mon Jul 17 23:27:17 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
Configuration (if not default, please attach mbedtls_config.h):
Compiler and options (if you used a pre-built binary, please indicate how you obtained it):
Additional environment information:
Expected behavior
No error for each requests.
Actual behavior
Random error is returned, including:
- -0x0001 - ERROR - Generic error
- -0x006e - ERROR - This is a bug in the library
- -0x7280 - SSL - The connection indicated an EOF
- -0x6e00 - SSL - The handshake negotiation failed
- core dumped
Steps to reproduce
-
Set config
scripts/config.py set MBEDTLS_SSL_PROTO_TLS1_3 scripts/config.py set MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE scripts/config.py set MBEDTLS_THREADING_PTHREAD scripts/config.py set MBEDTLS_THREADING_C
-
Update
./mbedtls-sys/vendor/programs/ssl/ssl_pthread_server.cwith https://gist.github.com/Taowyoo/e2a90ed25bf299500074fdf03e67a050#file-ssl_pthread_server-c -
Build and run example, example starts a server with 5 threads and spawn 5 threads of clients to connect it.
mkdir -p build cmake -S . -B ./build -DENABLE_PROGRAMS=ON -DENABLE_TESTING=OFF && cmake --build ./build ./build/programs/ssl/ssl_pthread_server
In ~70%, the client/server will failed with error.
Additional information
The script above can run successfully with TLS 1.2 or with TLS 1.3 + one thread for several time, but for TLS 1.3 + multi-thread the script failed in most cases.