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

initial Reader.HasNext() returns true on empty topic, leading to hangs. #438

Closed
flowchartsman opened this issue Jan 11, 2021 · 1 comment
Labels

Comments

@flowchartsman
Copy link
Contributor

I am creating a reader to stream the last of function output messages to a browser connection:

eader, err := s.pclient.CreateReader(
			pulsar.ReaderOptions{
				Topic:          common.TopicName(common.Tenant, common.NamespaceAgent, uuid),
				StartMessageID: pulsar.EarliestMessageID(),
				Name:           fmt.Sprintf("results_%s_%d", uuid, time.Now().UnixNano()),
			},
		)
		if err != nil {
			respond(w, errorResponse("failed to create reader: "+err.Error()), http.StatusInternalServerError)
			return
		}
		if err := reader.SeekByTime(time.Now().Add(-1 * time.Hour)); err != nil {
			respond(w, errorResponse("failed to seek reader: "+err.Error()), http.StatusInternalServerError)
			return
		}
		defer reader.Close()
		w.Write([]byte(resultsStart))
		for reader.HasNext() {
			msg, err := reader.Next(rctx)
			if err != nil {
				// if we encounter an error, add a dummy dict in case there's a comma, then close the list and add the error to the response
				fmt.Fprintf(w, `{}],"error":"error during results iteration: %s"}`, err)
				f.Flush()
				return
			}

Expected behavior

If there are no results, HasNext() should return false and the handler should proceed.

Actual behavior

Hangs forever.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants