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

kong.Response.Exit() Hanging #169

Closed
joeyagreco-sb opened this issue Jan 18, 2024 · 1 comment
Closed

kong.Response.Exit() Hanging #169

joeyagreco-sb opened this issue Jan 18, 2024 · 1 comment

Comments

@joeyagreco-sb
Copy link

joeyagreco-sb commented Jan 18, 2024

When calling Response.Exit(), code hangs.

Example for reproduction:

Set shouldExit to true, and the test hangs.
Set shouldExit to false and the test does not hang.

package main

import (
	"errors"
	"fmt"
	"net/http"
	"testing"

	"github.com/Kong/go-pdk"
	"github.com/stretchr/testify/assert"

	k "github.com/Kong/go-pdk/test"
)

type foo struct {
	shouldExit bool
}

func New() *foo {
	return &foo{
		// manually change me to see both ways
		shouldExit: true,
	}
}

func (f *foo) Response(kong *pdk.PDK) {
	if f.shouldExit {
		fmt.Println("im trying to exit early")
		kong.Response.Exit(http.StatusInternalServerError, []byte(errors.New("exit").Error()), nil)
	}
	fmt.Println("im done")
}

func TestFoo(t *testing.T) {
	t.Parallel()

	env, err := k.New(t, k.Request{
		Method: "POST",
		Url:    "",
		Body:   []byte("{}"),
	})
	assert.NoError(t, err)
	env.DoHttps(New())
}

I will note that kong.Response.ExitStatus() does not hang.

@gszr
Copy link
Member

gszr commented Feb 21, 2024

Fixed by #174

@gszr gszr closed this as completed Feb 21, 2024
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

Successfully merging a pull request may close this issue.

2 participants