@@ -155,8 +155,9 @@ ngx_[% subsys %]_lua_ffi_check_context(ngx_[% subsys %]_lua_ctx_t *ctx,
155155 SSL_get_ex_data(ssl_conn, ngx_[% subsys %]_lua_ssl_ctx_index)
156156
157157
158- lua_State * ngx_ [% subsys %]_lua_init_vm (lua_State * parent_vm , ngx_cycle_t * cycle ,
159- ngx_pool_t * pool , ngx_ [% subsys %]_lua_main_conf_t * lmcf , ngx_log_t * log ,
158+ ngx_int_t ngx_ [% subsys %]_lua_init_vm (lua_State * * new_vm , lua_State * parent_vm ,
159+ ngx_cycle_t * cycle , ngx_pool_t * pool ,
160+ ngx_ [% subsys %]_lua_main_conf_t * lmcf , ngx_log_t * log ,
160161 ngx_pool_cleanup_t * * pcln );
161162
162163lua_State * ngx_ [% subsys %]_lua_new_thread ([% req_type %] * r , lua_State * l ,
@@ -315,7 +316,8 @@ ngx_http_lua_create_ctx(ngx_http_request_t *r)
315316ngx_stream_lua_create_ctx (ngx_stream_session_t * r )
316317[% END %]
317318{
318- lua_State * L ;
319+ ngx_int_t rc ;
320+ lua_State * L = NULL ;
319321 ngx_ [% subsys %]_lua_ctx_t * ctx ;
320322 ngx_pool_cleanup_t * cln ;
321323 ngx_ [% subsys %]_lua_loc_conf_t * llcf ;
@@ -367,8 +369,8 @@ ngx_stream_lua_create_ctx(ngx_stream_session_t *r)
367369#endif
368370
369371[% IF http_subsys %]
370- L = ngx_http_lua_init_vm (lmcf -> lua , lmcf -> cycle , r -> pool , lmcf ,
371- r -> connection -> log , & cln );
372+ rc = ngx_http_lua_init_vm (& L , lmcf -> lua , lmcf -> cycle , r -> pool , lmcf ,
373+ r -> connection -> log , & cln );
372374
373375[% ELSIF stream_subsys %]
374376 /*
@@ -378,8 +380,8 @@ ngx_stream_lua_create_ctx(ngx_stream_session_t *r)
378380 * the correct semantics.
379381 */
380382
381- L = ngx_stream_lua_init_vm (lmcf -> lua , lmcf -> cycle , sreq -> pool , lmcf ,
382- r -> connection -> log , & cln );
383+ rc = ngx_stream_lua_init_vm (& L , lmcf -> lua , lmcf -> cycle , sreq -> pool ,
384+ lmcf , r -> connection -> log , & cln );
383385
384386 while (cln -> next != NULL ) {
385387 cln = cln -> next ;
@@ -392,11 +394,30 @@ ngx_stream_lua_create_ctx(ngx_stream_session_t *r)
392394 cln -> next = NULL ;
393395[% END %]
394396
395- if (L == NULL ) {
396- ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 ,
397- "failed to initialize Lua VM" );
398- return NULL ;
399- }
397+ if (rc != NGX_OK ) {
398+ if (rc == NGX_DECLINED ) {
399+ ngx_ [% subsys %]_lua_assert (L != NULL );
400+
401+ ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 ,
402+ "failed to load the 'resty.core' module "
403+ "(https://github.com/openresty/lua-resty"
404+ "-core); ensure you are using an OpenResty "
405+ "release from https://openresty.org/en/"
406+ "download.html (reason: %s)" ,
407+ lua_tostring (L , -1 ));
408+
409+ } else {
410+ /* rc == NGX_ERROR */
411+ ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 ,
412+ "failed to initialize Lua VM" );
413+ }
414+
415+ return NULL ;
416+ }
417+
418+ /* rc == NGX_OK */
419+
420+ ngx_ [% subsys %]_lua_assert (L != NULL );
400421
401422 if (lmcf -> init_handler ) {
402423 if (lmcf -> init_handler (r -> connection -> log , lmcf , L ) != NGX_OK ) {
0 commit comments