openresty / openresty/lua-nginx-module
Fake connection would not close, when failed to load external Lua file
Open
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 11.8k
- Forks
- 2.1k
- Avg merge
- 6h 1m
- Merged PRs (30d)
- 6
Description
config:
server {
listen 7023 ssl;
ssl_certificate_by_lua_file lua/ssl_choose_cert/shared_cert_pkey_choose.lua;
ssl_common_cert baidu.com.globalsign.cer;
ssl_common_key baidu.com.globalsign.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
...
}
Debug log:
2018/08/22 13:35:41 [debug] 16715#0: accept() not ready (11: Resource temporarily unavailable)
2018/08/22 13:35:41 [debug] 16714#0: posix_memalign: 000000000123DA60:512 @16
2018/08/22 13:35:41 [debug] 16714#0: *1955 accept: 127.0.0.1:16620 fd:1138
2018/08/22 13:35:41 [debug] 16714#0: *1955 event timer add: 1138: 60000:1534916201122
2018/08/22 13:35:41 [debug] 16714#0: *1955 reusable connection: 1
2018/08/22 13:35:41 [debug] 16714#0: *1955 epoll add event: fd:1138 op:1 ev:80002001
2018/08/22 13:35:41 [debug] 16714#0: accept() not ready (11: Resource temporarily unavailable)
2018/08/22 13:35:41 [debug] 16713#0: accept() not ready (11: Resource temporarily unavailable)
2018/08/22 13:35:41 [debug] 16714#0: *1955 http check ssl handshake
2018/08/22 13:35:41 [debug] 16714#0: *1955 http recv(): 1
2018/08/22 13:35:41 [debug] 16714#0: *1955 https ssl handshake: 0x16
2018/08/22 13:35:41 [debug] 16714#0: *1955 ssl cert: connection reusable: 1
lua *** ngx_http_lua_ssl_cert_handler: ssl cert handler, cert-ctx=(nil) at addon/lua-nginx-module-0.10.11/src/ngx_http_lua_ssl_certby.c line 205.
lua *** ngx_http_lua_ssl_cert_handler: first time at addon/lua-nginx-module-0.10.11/src/ngx_http_lua_ssl_certby.c line 222.
2018/08/22 13:35:41 [debug] 16714#0: *1955 reusable connection: 0
lua *** ngx_http_lua_create_fake_connection: created fake connection: 0x61284a0 at addon/lua-nginx-module-0.10.11/src/ngx_http_lua_util.c line 3887.
lua *** ngx_http_lua_create_fake_request: r pool allocated: 1168 at addon/lua-nginx-module-0.10.11/src/ngx_http_lua_util.c line 3913.
lua *** ngx_http_lua_create_fake_request: created fake request 0x34d24b0 at addon/lua-nginx-module-0.10.11/src/ngx_http_lua_util.c line 3975.
lua *** ngx_http_lua_ssl_cert_handler: setting cctx at addon/lua-nginx-module-0.10.11/src/ngx_http_lua_ssl_certby.c line 289.
lua *** ngx_http_lua_get_lua_vm: lmcf->lua: 0x45001378 at addon/lua-nginx-module-0.10.11/src/ngx_http_lua_util.h line 333.
lua *** ngx_http_lua_cache_loadfile: CACHE file key already pre-calculated at addon/lua-nginx-module-0.10.11/src/ngx_http_lua_cache.c line 227.
lua *** ngx_http_lua_cache_loadfile: XXX cache key for file: [nhlf_e37be5c3eb165e8696234ba1ddfc7dcf] at addon/lua-nginx-module-0.10.11/src/ngx_http_lua_cache.c line 230.
lua *** ngx_http_lua_cache_load_code: Code cache table to load: 0x45009b98 at addon/lua-nginx-module-0.10.11/src/ngx_http_lua_cache.c line 45.
lua *** ngx_http_lua_cache_load_code: Value associated with given key in code cache table is not code chunk: stack top=2, top value type=no value
at addon/lua-nginx-module-0.10.11/src/ngx_http_lua_cache.c line 80.
lua *** ngx_http_lua_cache_loadfile: Code cache missed! cache key='nhlf_e37be5c3eb165e8696234ba1ddfc7dcf', stack top=0, file path='/home/work/jorcol/lua/ssl_choose_cert/shared_cert_pkey_choose.lua' at addon/lua-nginx-module-0.10.11/src/ngx_http_lua_cache.c line 247.
lua *** ngx_http_lua_cache_loadfile: loadfile returns 6 (6) at addon/lua-nginx-module-0.10.11/src/ngx_http_lua_cache.c line 252.
2018/08/22 13:35:41 [error] 16714#0: *1956 failed to load external Lua file "/home/work/jorcol/lua/ssl_choose_cert/shared_cert_pkey_choose.lua": cannot open /home/work/jorcol/lua/ssl_choose_cert/shared_cert_pkey_choose.lua: No such file or directory, context: ssl_certificate_by_lua*, client: 127.0.0.1, server: 0.0.0.0:7023
2018/08/22 13:35:41 [debug] 16714#0: *1955 lua_certificate_by_lua: handler return value: 404, cert cb exit code: 1
2018/08/22 13:35:41 [debug] 16714#0: *1955 SSL_do_handshake: -1
2018/08/22 13:35:41 [debug] 16714#0: *1955 SSL_get_error: 2
2018/08/22 13:35:41 [debug] 16714#0: *1955 reusable connection: 0
2018/08/22 13:35:41 [debug] 16714#0: *1955 SSL handshake handler: 0
2018/08/22 13:35:41 [debug] 16714#0: *1955 ssl session ticket encrypt, key: "169d770cde203e94557f8a18fa8e5ccf" (new session)
2018/08/22 13:35:41 [debug] 16714#0: *1955 SSL_do_handshake: 1
2018/08/22 13:35:41 [debug] 16714#0: *1955 SSL: TLSv1.2, cipher: "ECDHE-RSA-AES128-GCM-SHA256 TLSv1.2 Kx=ECDH Au=RSA Enc=AESGCM(128) Mac=AEAD"
2018/08/22 13:35:41 [debug] 16714#0: *1955 reusable connection: 1
2018/08/22 13:35:41 [debug] 16714#0: *1955 http wait request handler
2018/08/22 13:35:41 [debug] 16714#0: *1955 posix_memalign: 0000000005EB9A60:512 @16
2018/08/22 13:35:41 [debug] 16714#0: *1955 malloc: 0000000005EB9C70:1024
2018/08/22 13:35:41 [debug] 16714#0: *1955 SSL_read: -1
2018/08/22 13:35:41 [debug] 16714#0: *1955 SSL_get_error: 2
2018/08/22 13:35:41 [debug] 16714#0: *1955 free: 0000000005EB9C70
2018/08/22 13:35:42 [debug] 16714#0: *1955 http wait request handler
patch:
addon/lua-nginx-module-0.10.11/src/ngx_http_lua_ssl_certby.c
@@ -48,6 +48,7 @@ ngx_http_lua_ssl_cert_handler_file(ngx_http_request_t *r,
lscf->srv.ssl_cert_src.data,
lscf->srv.ssl_cert_src_key);
if (rc != NGX_OK) {
+ ngx_http_lua_finalize_request(r, NGX_DONE);
return rc;
}
Fake connection would close, as:
2018/08/22 13:57:48 [debug] 19103#0: accept() not ready (11: Resource temporarily unavailable)
2018/08/22 13:57:48 [debug] 19104#0: posix_memalign: 0000000001433450:512 @16
2018/08/22 13:57:48 [debug] 19104#0: *9685 accept: 127.0.0.1:47807 fd:1136
2018/08/22 13:57:48 [debug] 19104#0: *9685 event timer add: 1136: 60000:1534917528671
2018/08/22 13:57:48 [debug] 19104#0: *9685 reusable connection: 1
2018/08/22 13:57:48 [debug] 19104#0: *9685 epoll add event: fd:1136 op:1 ev:80002001
2018/08/22 13:57:48 [debug] 19104#0: accept() not ready (11: Resource temporarily unavailable)
2018/08/22 13:57:48 [debug] 19104#0: *9685 http check ssl handshake
2018/08/22 13:57:48 [debug] 19104#0: *9685 http recv(): 1
2018/08/22 13:57:48 [debug] 19104#0: *9685 https ssl handshake: 0x16
2018/08/22 13:57:48 [debug] 19104#0: *9685 ssl cert: connection reusable: 1
lua *** ngx_http_lua_ssl_cert_handler: ssl cert handler, cert-ctx=(nil) at addon/lua-nginx-module-0.10.11/src/ngx_http_lua_ssl_certby.c line 207.
lua *** ngx_http_lua_ssl_cert_handler: first time at addon/lua-nginx-module-0.10.11/src/ngx_http_lua_ssl_certby.c line 224.
2018/08/22 13:57:48 [debug] 19104#0: *9685 reusable connection: 0
lua *** ngx_http_lua_create_fake_connection: created fake connection: 0x61284a0 at addon/lua-nginx-module-0.10.11/src/ngx_http_lua_util.c line 3887.
lua *** ngx_http_lua_create_fake_request: r pool allocated: 1168 at addon/lua-nginx-module-0.10.11/src/ngx_http_lua_util.c line 3913.
lua *** ngx_http_lua_create_fake_request: created fake request 0x34d24b0 at addon/lua-nginx-module-0.10.11/src/ngx_http_lua_util.c line 3975.
lua *** ngx_http_lua_ssl_cert_handler: setting cctx at addon/lua-nginx-module-0.10.11/src/ngx_http_lua_ssl_certby.c line 291.
lua *** ngx_http_lua_get_lua_vm: lmcf->lua: 0x45001378 at addon/lua-nginx-module-0.10.11/src/ngx_http_lua_util.h line 333.
lua *** ngx_http_lua_cache_loadfile: CACHE file key already pre-calculated at addon/lua-nginx-module-0.10.11/src/ngx_http_lua_cache.c line 227.
lua *** ngx_http_lua_cache_loadfile: XXX cache key for file: [nhlf_e37be5c3eb165e8696234ba1ddfc7dcf] at addon/lua-nginx-module-0.10.11/src/ngx_http_lua_cache.c line 230.
lua *** ngx_http_lua_cache_load_code: Code cache table to load: 0x45009b98 at addon/lua-nginx-module-0.10.11/src/ngx_http_lua_cache.c line 45.
lua *** ngx_http_lua_cache_load_code: Value associated with given key in code cache table is not code chunk: stack top=2, top value type=no value
at addon/lua-nginx-module-0.10.11/src/ngx_http_lua_cache.c line 80.
lua *** ngx_http_lua_cache_loadfile: Code cache missed! cache key='nhlf_e37be5c3eb165e8696234ba1ddfc7dcf', stack top=0, file path='/home/work/jorcol/lua/ssl_choose_cert/shared_cert_pkey_choose.lua' at addon/lua-nginx-module-0.10.11/src/ngx_http_lua_cache.c line 247.
lua *** ngx_http_lua_cache_loadfile: loadfile returns 6 (6) at addon/lua-nginx-module-0.10.11/src/ngx_http_lua_cache.c line 252.
2018/08/22 13:57:48 [error] 19104#0: *9686 failed to load external Lua file "/home/work/jorcol/lua/ssl_choose_cert/shared_cert_pkey_choose.lua": cannot open /home/work/jorcol/lua/ssl_choose_cert/shared_cert_pkey_choose.lua: No such file or directory, context: ssl_certificate_by_lua*, client: 127.0.0.1, server: 0.0.0.0:7023
2018/08/22 13:57:48 [debug] 19104#0: *9686 http lua finalize fake request: -4, a:1, c:1
2018/08/22 13:57:48 [debug] 19104#0: *9686 http lua fake request count:1
2018/08/22 13:57:48 [debug] 19104#0: *9686 http lua close fake request
2018/08/22 13:57:48 [debug] 19104#0: *9686 http lua close fake http connection 00000000061284A0
2018/08/22 13:57:48 [debug] 19104#0: *9685 lua_certificate_by_lua: handler return value: 404, cert cb exit code: 1
2018/08/22 13:57:48 [debug] 19104#0: *9685 SSL_do_handshake: -1
2018/08/22 13:57:48 [debug] 19104#0: *9685 SSL_get_error: 2
2018/08/22 13:57:48 [debug] 19104#0: *9685 reusable connection: 0
2018/08/22 13:57:48 [debug] 19104#0: *9685 SSL handshake handler: 0
2018/08/22 13:57:48 [debug] 19104#0: *9685 ssl session ticket encrypt, key: "169d770cde203e94557f8a18fa8e5ccf" (new session)
2018/08/22 13:57:48 [debug] 19104#0: *9685 SSL_do_handshake: 1
2018/08/22 13:57:48 [debug] 19104#0: *9685 SSL: TLSv1.2, cipher: "ECDHE-RSA-AES128-GCM-SHA256 TLSv1.2 Kx=ECDH Au=RSA Enc=AESGCM(128) Mac=AEAD"
2018/08/22 13:57:48 [debug] 19104#0: *9685 reusable connection: 1
2018/08/22 13:57:48 [debug] 19104#0: *9685 http wait request handler
GaoYan
Thanks
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in addon/lua-nginx-module-0.10.11/src/ngx_http_lua_ssl_certby.c, at ngx_http_lua_ssl_cert_handler_file and the external Lua file loading failure path. Reproduce the shown configuration with a missing lua/ssl_choose_cert/shared_cert_pkey_choose.lua file, then verify that the fake request and fake connection close as shown in the later debug log.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, lua
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100