Content-Length: 218445 | pFad | http://github.com/ThreeDotsLabs/watermill/issues/562

9C Context timeout ignored in Watermill's Google PubSub publisher due to premature `Ready()` blocking · Issue #562 · ThreeDotsLabs/watermill · GitHub
Skip to content

Context timeout ignored in Watermill's Google PubSub publisher due to premature Ready() blocking #562

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

Open
dineshgowda24 opened this issue May 5, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@dineshgowda24
Copy link

Steps to reproduce

package main

import (
	"time"

	"github.com/ThreeDotsLabs/watermill"
	"github.com/ThreeDotsLabs/watermill-googlecloud/pkg/googlecloud"
	"github.com/ThreeDotsLabs/watermill/message"
	"github.com/google/uuid"
	"google.golang.org/api/option"
)

func main() {
	opts := []option.ClientOption{
		option.WithCredentialsJSON([]byte("<replace-credentials>")),
	}

	cfg := googlecloud.PublisherConfig{
		Marshaler:                 googlecloud.DefaultMarshalerUnmarshaler{},
		ProjectID:                 "<replace-project-id>",
		ClientOptions:             opts,
		DoNotCreateTopicIfMissing: false,
		DoNotCheckTopicExistence:  true,
		PublishTimeout:            1 * time.Nanosecond, // Simulate context cancellation by setting a very low timeout
	}

	publisher, err := googlecloud.NewPublisher(cfg, watermill.NopLogger{})
	if err != nil {
		panic(err)
	}

	payload := `{"message": "hello world!"}`
	msgId := uuid.New().String()
	publisher.Publish("<replace-topic-id>", message.NewMessage(msgId, message.Payload(payload)))
}

Expected behavior

  1. The underlying publisher should return an error when the provided context times out.

Actual behavior

  1. The publish timeout is not respected — the publisher blocks indefinitely, even after exceeding the context deadline.

Possible solution

The root cause lies in the following lines:

https://github.com/ThreeDotsLabs/watermill-googlecloud/blob/4a22a44b6cdbe7c270cb1e0fc3355f97141645ee/pkg/googlecloud/publisher.go#L166C1-L169C42

result := t.Publish(ctx, googlecloudMsg)
<-result.Ready()

serverMessageID, err := result.Get(ctx)

We're blocking on <-result.Ready() before calling Get(ctx). According to the Get implementation in the Google Cloud Pub/Sub client:

If the result is already ready, Get returns immediately — even if the context is already done.

Since we're explicitly waiting on Ready() before calling Get, the context is essentially ignored, and Get(ctx) will always return the result, regardless of context timeout.

A potential fix is to remove the <-result.Ready() line, allowing Get(ctx) to handle both Ready and respecting the context deadline.

@dineshgowda24 dineshgowda24 added the bug Something isn't working label May 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/ThreeDotsLabs/watermill/issues/562

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy