https://github.com/rgiaviti/bug-go-kong-reference-error
Sample project to reproduce a bug using go-kong
https://github.com/rgiaviti/bug-go-kong-reference-error
bug go-kong sample-project
Last synced: 3 months ago
JSON representation
Sample project to reproduce a bug using go-kong
- Host: GitHub
- URL: https://github.com/rgiaviti/bug-go-kong-reference-error
- Owner: rgiaviti
- License: mit
- Created: 2022-02-23T16:32:48.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-02-24T11:53:41.000Z (about 4 years ago)
- Last Synced: 2024-06-19T21:02:21.343Z (almost 2 years ago)
- Topics: bug, go-kong, sample-project
- Language: Go
- Homepage:
- Size: 3.64 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Go-Kong Bug
This is a sample Go project to simulate a detected bug in go-kong v0.28.0. Issue opened [here](https://github.com/Kong/go-kong/issues/137)
## When the bug happens
When we try to validate a plugin schema using [go-kong](https://github.com/Kong/go-kong) and the target kong is offline
(or even if the Admin API was disabled), we get a reference error because the response is `nil`.
## Steps to reproduce
### Deploy a Kong with AdminAPI Enabled
```
$ docker run -d --name kong \
-e "KONG_DATABASE=off" \
-e "KONG_PROXY_ACCESS_LOG=/dev/stdout" \
-e "KONG_ADMIN_ACCESS_LOG=/dev/stdout" \
-e "KONG_PROXY_ERROR_LOG=/dev/stderr" \
-e "KONG_ADMIN_ERROR_LOG=/dev/stderr" \
-e "KONG_ADMIN_LISTEN=0.0.0.0:8001, 0.0.0.0:8444 ssl" \
-e "KONG_PLUGINS=bundled" \
-p 8000:8000 \
-p 8443:8443 \
-p 8001:8001 \
-p 8444:8444 \
kong
```
### Check if AdminAPI is responding in Port 8001
```
curl --location --request GET 'http://localhost:8001/status'
```
Status Code must be `200 OK`
### Run the Program
```
$ go run main.go
```
### Result
One function will validate a plugin with success. The other function will crash go-kong.
```
Reproducing bug...
Calling AdminAPI in Port 8001
validation of correlation-id
result: true
message:
Calling AdminAPI in Port 9000
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x76792c]
goroutine 1 [running]:
github.com/kong/go-kong/kong.(*PluginService).Validate(0xc0000b0040, {0x81bdb0, 0xc0000240b8}, 0xc0000b4000)
/home/rgiaviti/go/pkg/mod/github.com/kong/go-kong@v0.28.1/kong/plugin_service.go:186 +0x26c
main.CallingIncorrectKongPort()
/home/rgiaviti/Desktop/bug-go-kong-reference-error/main.go:41 +0x123
main.main()
/home/rgiaviti/Desktop/bug-go-kong-reference-error/main.go:12 +0x70
```