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

auto/lib/openssl/make: no-threads选项与enable-async选项似乎是冲突的, 导致异步模式无法生效 #1954

Open
chenxuqiang opened this issue Aug 8, 2024 · 0 comments
Assignees

Comments

@chenxuqiang
Copy link

openssl编译选项中no-threads选项与enable-async选项似乎是冲突的

我在尝试使用openssl源码库作为依赖编译Tengine时,使用了如下的配置:

./configure --with-http_ssl_module --prefix=${install_path} --with-openssl=${openssl_src_path} --with-http_v2_module --with-openssl-async --with-openssl-opt=enable-async

nginx被成功编译出来了,同时我启用了ssl_async on的配置;此时我使用

curl -k https://localhost:443/index.html

拉取index.html,报了如下错误:

[root@localhost logs]# curl -k https://localhost:443/index.html
curl: (35) OpenSSL SSL_connect: Connection reset by peer in connection to localhost:443

当我使用gdb调试时,发现它在
openssl/crypto/async/async.c中的ASYNC_start_job()函数中的async_fibre_swapcontext函数处返回了错误。于是我怀疑是openssl 的async功能没有真正的生效。于是我编写了一个异步测试程序进行测试,该测试程序源码如下:

#include <openssl/async.h>
#include <openssl/err.h>
#include <stdio.h>
#include <stdlib.h>

void test_func(void *arg) {
    printf("Async function is running.\n");
    ASYNC_pause_job();
    printf("Async function is resumed.\n");
}

int main() {
    ASYNC_JOB *job = NULL;
    ASYNC_WAIT_CTX *ctx = ASYNC_WAIT_CTX_new();
    int ret;

    if (!ASYNC_init_thread(1, 0)) {
        printf("Failed to init async threads.\n");
        return 1;
    }

    ret = ASYNC_start_job(&job, ctx, &ret, test_func, NULL, 0);
    if (ret == ASYNC_PAUSE) {
        printf("Async job paused, waiting for resume.\n");
        ret = ASYNC_start_job(&job, ctx, &ret, test_func, NULL, 0);
    }

    if (ret == ASYNC_FINISH) {
        printf("ASYNC job finished successfully\n");
    } else {
        printf("ASYNC job failed with status: %d\n", ret);
    }

    ASYNC_cleanup_thread();
    return 0;
}

编译该程序:

gcc openssl_test.c -o openssl_test ${openssl_src_path}/.openssl/lib/libcrypto.a

其中${openssl_src_path}/.openssl是nginx默认的openssl安装路径。执行该测试程序,理论上应该有如下预期输出:

[root@localhost openssl_test]# ./openssl_test 
Async function is running.
Async job paused, waiting for resume.
Async function is resumed.
ASYNC job finished successfully

但是我们测试中发现它的输出是这样的:

[root@localhost openssl_test]# ./openssl_test 
ASYNC job failed with status: 1

这说明异步功能确实存在问题,我又手动重新编译了一次openssl, 在config时,只加入了enable-async的选项。这一次重新链接运行,其功能是正确,符合预期的。
于是我在NGINX/auto/lib/openssl/make中去掉了no-threads选项,重新编译之后,openssl_test测试程序也通过了,同时nginx使用wrk和curl进行测试均能够通过测试了。

[root@localhost logs]# curl -k https://localhost:444/index.html
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

所以这里我有个怀疑,async应该是依赖theads的功能的。在原始的NGINX里面由于不支持async,no-threads似乎没有什么影响,但是在Tengine中支持了async, 这里感觉似乎不太合理。他们之前加上no-threads的原因我看了一下,没有看太懂。
Configure: restored "no-threads" in OpenSSL builds. 。不知道你们有没有测试过这个情况(当然我这里没有使用硬件加速器等异步设备)。

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

No branches or pull requests

2 participants