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

go plugin excute time >= 60s will cause error (event callback failed; source=plugin_server, event=reset_instances) #13210

Closed
1 task done
xyandy opened this issue Jun 14, 2024 · 8 comments
Labels
pending author feedback Waiting for the issue author to get back to a maintainer with findings, more details, etc...

Comments

@xyandy
Copy link

xyandy commented Jun 14, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Kong version ($ kong version)

kong:3.5

Current Behavior

i write a golang plugin. It sleep xxx seconds and then return response. codes are below:

package main

import (
	"fmt"
	"net/http"
	"time"

	"github.com/Kong/go-pdk"
	"github.com/Kong/go-pdk/server"
)

func main() {
	var version = "0.1"
	var priority = 100
	server.StartServer(New, version, priority)
}

type Config struct {
	Timeout int `json:"timeout"`
}

func New() interface{} {
	return &Config{
		Timeout: 10,
	}
}

func (conf Config) Access(kong *pdk.PDK) {
	method, _ := kong.Request.GetMethod()
	path, _ := kong.Request.GetPath()
	bodyBytes, _ := kong.Request.GetRawBody()
	str := fmt.Sprintf("method: %s, path: %s, body: %s", method, path, string(bodyBytes))

	kong.Log.Notice(str)
	time.Sleep(time.Duration(conf.Timeout) * time.Second)
	kong.Response.Exit(http.StatusOK, []byte(str), nil)
}

If the timeout >= 60s, it will return the below error:
image

Expected Behavior

Can we provide a argument that could set up the plugin event callback timeout ?

Steps To Reproduce

No response

Anything else?

No response

@xyandy xyandy changed the title go plugin excute time >= 60s will cause error go plugin excute time >= 60s will cause error (event callback failed; source=plugin_server, event=reset_instances) Jun 14, 2024
@git-hulk
Copy link
Contributor

This bug seems to have been resolved by #11819.

@xyandy
Copy link
Author

xyandy commented Jun 18, 2024

This bug seems to have been resolved by #11819.

image

This PR is merged on Nov 7, 2023. But kong 3.5 is released on Nov 8, 2023...
Looks like Kong 3.5 contains this pr changes? But it doesn't work ?

@git-hulk
Copy link
Contributor

@xyandy I believe you can check this by taking a look at the commit history of 3.5.0 instead of by date only.

This PR commit was first released in 3.6.0:
image

@StarlightIbuki StarlightIbuki added the pending author feedback Waiting for the issue author to get back to a maintainer with findings, more details, etc... label Jun 18, 2024
@StarlightIbuki
Copy link
Contributor

Please try with 3.6 to see if the issue persists.

@xyandy
Copy link
Author

xyandy commented Jun 18, 2024

image I tried kong:3.7. It works and will not report the error (event callback failed; source=plugin_server, event=reset_instances)

But can we just increment the timeout that nginx lua call go plugin server?

Let's assume a scenario:

We wanna call a backend api to check if the request Authorization header is valid in plugin Access(pdk) function.
The backend api is slow and it spends about 61s.

We think it is ok. But now, it will report [plugin] timeout...

@StarlightIbuki
Copy link
Contributor

Actually, it's possible: lua_socket_connect_timeout can be used.

@xyandy
Copy link
Author

xyandy commented Jun 18, 2024

I deploy kong:3.7 in k8s.. add container env: KONG_NGINX_HTTP_LUA_SOCKET_CONNECT_TIMEOUT=80
image

But it seems that it doesn't work... after 60s, it logs [plugin] timeout
image
image

@xyandy
Copy link
Author

xyandy commented Jun 18, 2024

OK, just set lua_socket_read_timeout solves this problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending author feedback Waiting for the issue author to get back to a maintainer with findings, more details, etc...
Projects
None yet
Development

No branches or pull requests

3 participants