Kong / kong

🦍 The Cloud-Native API Gateway and AI Gateway.
https://konghq.com/install/
Apache License 2.0
39.41k stars 4.83k forks source link

Kong go plugin - kong.Response.Exit throws error #6108

Closed heliortf closed 4 years ago

heliortf commented 4 years ago

Hello you all.

I'm developing some plugins for Kong using go plugin structure. But when I try to output a simple response in Access phase im getting the following error in the log file: /usr/local/kong/logs/error.log:

2020/07/14 10:25:00 [error] 53#0: *71 recv() failed (104: Connection reset by peer), client: 172.20.0.1, server: kong, request: "GET /produtos/5PKfpT9BmAlOt7Y4Pp3a HTTP/1.1", host: "localhost"
2020/07/14 10:25:00 [debug] 53#0: *71 [lua] init.lua:888: balancer(): setting address (try 1): 192.168.65.2:5001
2020/07/14 10:25:00 [debug] 53#0: *71 [lua] init.lua:917: balancer(): enabled connection keepalive (pool=192.168.65.2|5001, pool_size=60, idle_timeout=60, max_requests=100)
2020/07/14 10:25:00 [notice] 53#0: signal 17 (SIGCHLD) received from 62
2020/07/14 10:25:00 [notice] 53#0: *4 [kong] go.lua:97 go-pluginserver terminated: exit 2, context: ngx.timer
2020/07/14 10:25:00 [notice] 53#0: *4 [kong] go.lua:86 Starting go-pluginserver, context: ngx.timer

Steps To Reproduce

  1. Create a plugin using Access phase and run the following code:
headers := make(map[string][]string)
headers["Content-Type"] = []string{"application/json; charset=utf-8"}
kong.Response.Exit(200, `{"success":true}`, headers)

In Postman, when hit this route i get the response:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <title>Error</title>
</head>

<body>
    <pre>Cannot GET /produtos/5PKfpT9BmAlOt7Y4Pp3a</pre>
</body>

</html>

Additional Details & Logs

kikito commented 4 years ago

Hi, some things are not completely stable in 2.1.0beta1. Have you tried 2.1.0rc.1?

Also, please tell us whether you can reproduce the problem if you try to execute a plugin with an empty access method.

javierguerragiraldez commented 4 years ago

Hi @heliortf I've tried to reproduce the issue, but everything works ok. Besides the point from @kikito , I remember that some of the kong.Response methods changed a bit around the first beta time. Please check you're using the latest Go PDK and try again.

Closing this issue now, feel free to reopen if you still see this problem.