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

Unexpected behavior with async produce context #859

Open
echo8 opened this issue Nov 14, 2024 · 0 comments
Open

Unexpected behavior with async produce context #859

echo8 opened this issue Nov 14, 2024 · 0 comments

Comments

@echo8
Copy link

echo8 commented Nov 14, 2024

I'm using this client's producer in an HTTP service but am running into some unexpected behavior regarding context usage.

Here is a simple example:

func httpHandler(w http.ResponseWriter, r *http.Request) {
	record := &kgo.Record{
		// ...
		Context: context.Background(),
	}
	client.Produce(r.Context(), record, producePromise)
	w.WriteHeader(http.StatusNoContent)
}

func producePromise(r *kgo.Record, err error) {
	if err != nil {
		log.Println("Produce failed.", err)
	} else {
		log.Println("Produce succeeded.")
	}
}

When I call this HTTP endpoint Produce failed. context canceled is logged. So it seems that the canceling of the request's context is causing the buffered record to also be canceled. This is unexpected to me because the record's context is being set to a totally different (background) context. In this case shouldn't the request's context only be used until the record is buffered?

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

1 participant