openresty / lua-resty-limit-traffic

Lua library for limiting and controlling traffic in OpenResty/ngx_lua
819 stars 150 forks source link

Graceful way to "leave" connection while handling error #32

Closed A-Scott-Rowe closed 4 years ago

A-Scott-Rowe commented 6 years ago

We are using incoming and leaving the same was as in the example in the readme. however when the server errors we redirect to an error page, this causes the context to be cleared and we lose the saved connection.

is there a more graceful way to leave the connection in this situation other than opening a new connection in the error handling code?

downtown12 commented 4 years ago

i meet the same problem, the concurrent level will increase in case of upstream connection errors

spacewander commented 4 years ago

What about using https://github.com/tokers/lua-resty-ctxdump to stash ctx before proxy and apply it back in log_by_lua/error_page block?

downtown12 commented 4 years ago

@spacewander Thanks. I have tested. It seems lua-resty-ctxdump module can solve the internal requests losing main request's ctx problem.

spacewander commented 4 years ago

The ctx is cleared by Nginx when it does internal redirect. As the workaround works I decide to close this issue. Feel free to reopen it if you still have problem.