You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2020/05/06 18:32:19 UTC

[GitHub] [pulsar] phemmer opened a new issue #6901: HasNext incorrectly reports next value available.

phemmer opened a new issue #6901:
URL: https://github.com/apache/pulsar/issues/6901


   **Describe the bug**
   Whenever a topic has messages on it, using `HasNext()` reports `true`, even if there are no messages at or after the cursor position.
   
   Not sure if this is limited to Go, but I doubt it since it's just a thin layer on top of the C client.
   
   **To Reproduce**
   Run:
   ```
   pulsar-admin namespaces create public/test
   pulsar-admin namespaces set-retention public/test --time -1 --size -1
   ```
   ```go
   package main
   
   import (
   	"context"
   	"fmt"
   	"os"
   	"time"
   
   	"github.com/apache/pulsar/pulsar-client-go/pulsar"
   )
   
   func main() {
   	if err := Main(); err != nil {
   		fmt.Fprintf(os.Stderr, "Error: %s\n", err)
   		os.Exit(1)
   	}
   	os.Exit(0)
   }
   
   func Main() error {
   	client, err := pulsar.NewClient(pulsar.ClientOptions{
   		URL: "pulsar://localhost:6650",
   	})
   	if err != nil { return err }
   
   	producer, err := client.CreateProducer(pulsar.ProducerOptions{
   		Topic: "persistent://public/test/test",
   	})
   	if err != nil { return err }
   
   	err = producer.Send(context.Background(), pulsar.ProducerMessage{Payload: []byte("test")})
   	if err != nil { return err }
   
   	consumer, err := client.CreateReader(pulsar.ReaderOptions{
   		Topic: "persistent://public/test/test",
   		StartMessageID: pulsar.LatestMessage,
   	})
   
   	hasnext, err := consumer.HasNext()
   	if err != nil { return err }
   	fmt.Printf("HasNext: %v\n", hasnext)
   
   	deadline, _ := context.WithDeadline(context.Background(), time.Now().Add(time.Second))
   	next, err := consumer.Next(deadline)
   	if err != nil { return err }
   	fmt.Printf("Next: %+v\n", next)
   
   	return nil
   }
   ```
   
   **Expected behavior**
   Should output `HasNext: false`
   
   **Screenshots**
   ```
   2020/05/06 14:29:17.854 c_client.go:68: [info] INFO  | ConnectionPool:85 | Created connection for pulsar://localhost:6650
   2020/05/06 14:29:17.856 c_client.go:68: [info] INFO  | ClientConnection:330 | [127.0.0.1:50238 -> 127.0.0.1:6650] Connected to broker
   2020/05/06 14:29:17.865 c_client.go:68: [info] INFO  | HandlerBase:53 | [persistent://public/test/test, ] Getting connection from pool
   2020/05/06 14:29:17.871 c_client.go:68: [info] INFO  | ProducerImpl:151 | [persistent://public/test/test, ] Created producer on broker [127.0.0.1:50238 -> 127.0.0.1:6650] 
   2020/05/06 14:29:17.874 c_client.go:68: [info] INFO  | HandlerBase:53 | [persistent://public/test/test, reader-d7bf639c4c, 0] Getting connection from pool
   2020/05/06 14:29:17.878 c_client.go:68: [info] INFO  | ConsumerImpl:170 | [persistent://public/test/test, reader-d7bf639c4c, 0] Created consumer on broker [127.0.0.1:50238 -> 127.0.0.1:6650] 
   HasNext: true
   Error: context deadline exceeded
   ```
   
   **Desktop (please complete the following information):**
    - OS: Linux - Fedora 31
   
   **Additional context**
   Add any other context about the problem here.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org