Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello everyone,
In one of our customers, we use this (amazing) library to behave like a lightweight and fast oidc reverse proxy (deployed as a k8s sidecar along with SPA applications).
To be able to proxy page requests and also ajax requests, we configured the proxy to have two default actions (for non authenticated requests):
However, after some time we started to notice intermittent failures with the ajax requests. The request failed but the session was valid (so it wasn't because HTTP session expiration, SSO session revoked, etc.).
On the openresty logs we found this error:
2020/02/06 18:32:57 [error] 8#8: *11162 [lua] openidc.lua:1406: authenticate(): lost access token:accessing token endpoint (https://sso.acme.com/auth/realms/realm/protocol/openid-connect/token) failed: closed, client: x.x.x.x, server: frontend.project.svc, request: "GET / HTTP/1.1", host: "frontend.acme.com", referrer: "https://frontend.acme.com/api"
After some research we figured out that the lua-resty-openidc uses a library called lua-resty-http to make calls to the OP.
This library (lua-resty-http) by default enables keepalive on the connections so it can create a connection pool to cache and reuse them later. This is necessary for a lot of good reasons (mostly performance related), but for some cases this behaviour can generate this issues, because the connection eventually will be closed and in my case this intermittent errors caused unnecessary api retries and extra traffic.
The idea of this PR is to make it possible for the user to enable or disable keepalive on the lua-resty-http library (just like the ssl_verify option).
The default behaviour would be to keep the keepalive enabled, to avoid causing problems with other users.
Regards,