matsumotory / ngx_mruby

ngx_mruby - A Fast and Memory-Efficient Web Server Extension Mechanism Using Scripting Language mruby for nginx
https://ngx.mruby.org/
988 stars 112 forks source link

Improve fiber gc registration #520

Closed kyswtnb closed 9 months ago

kyswtnb commented 9 months ago

Hello!!

@matsumotory Please review.

When repeatedly performing Nginx::Async.sleep, it overflows the value of MRB_ARY_LENGTH_MAX, resulting in the following error.

https://github.com/matsumotory/ngx_mruby/blob/af4228888587680d2c44b0aebbfb91e6e470d219/mruby/src/array.c#L26-L29

The issue also occurs with ngx_mruby v2.5.0.

There might be a misunderstanding on my part, or something missing. Please point out any discrepancies or omissions.

After looking into it, it appears that the error is occurring because mrb_gc_register is executed on every sleep operation. If mrb_gc_register is run at the start of the fiber and mrb_gc_unregister is run at the end of the fiber, the error will no longer occur.

I tried creating a PR. Please check it.

Pull-Request Check List

matsumotory commented 9 months ago

Thanks @kyswtnb !