Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apparently the data set into shared context is not being freed #204

Open
lays147 opened this issue May 8, 2024 · 2 comments
Open

Apparently the data set into shared context is not being freed #204

lays147 opened this issue May 8, 2024 · 2 comments

Comments

@lays147
Copy link

lays147 commented May 8, 2024

I have a plugin that sets a string to the Shared Context of Kong to be used in other plugins.
We noted that the memory consumption of the container increases during the workday. Apparently, the unused data is not being freed.

Based on the docs, it says that the data only exists during the existence of the request, so in my interpretation, when the request is over, the memory used would be freed, however, this does not seem the case.

I've already disabled the plugin during one day, and the memory consumption stabilizes.

image

Any idea how to handle this issue?

@77Vincent
Copy link

Hi @lays147
I had a memory issue recently with KONG plugin written in Golang as well, could you please kindly share more code detail? It may help the investigation a lot, thanks!

@lays147
Copy link
Author

lays147 commented Jun 12, 2024

Hi @77Vincent , here is the snippet:

func (conf AzureAuthConfig) Access(kong *pdk.PDK) {
	bearerToken, err := kong.Request.GetHeader("Authorization")

	if err != nil || bearerToken == "" {
		log.Warn().Err(err).Msg("Error on retrieving Authorization header")
		payload := jsonpayload.PreparePayload(PluginName, 400, "", "Missing Authorization header", "")
		kong.Response.Exit(400, payload, jsonpayload.JsonHeader())
		return
	}

	isJwtValid := IsJwtValid(bearerToken, conf.TenantId, conf.ClientId)

	if !isJwtValid.IsValid {
		payload := jsonpayload.PreparePayload(PluginName, 401, "", isJwtValid.InvalidReason, "")
		kong.Response.Exit(401, payload, jsonpayload.JsonHeader())
		return
	}

	err = kong.Ctx.SetShared(conf.JWTContextKey, isJwtValid.RawJwt)
	if err != nil {
		message := "Error on saving JWT token into Kong Context."
		log.Error().Err(err).Msg(message)
		payload := jsonpayload.PreparePayload(PluginName, 500, "", message, "")
		kong.Response.Exit(500, payload, jsonpayload.JsonHeader())
		return
	}
}

The rest of the plugin can be found here. The only difference is that the corporate version of the plugin that I developed sets the JWT to the Kong cache, as shown in the snippet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants