-
Notifications
You must be signed in to change notification settings - Fork 227
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
Duplicate subscription names silently fail #122
Comments
@stephenplusplus I'm not sure on the origin of this code, but it looks like its been around for quite some time. Do you have any insights on why we swallow this error? |
It looks like it came from the big redesign: https://github.com/GoogleCloudPlatform/google-cloud-node/pull/2380/files A code 6 is a 409 Conflict. I assume we're swallowing that error because if the user is trying to create something that already exists, the fact that it already does means "job done!" @jasonwilson sorry, but I wasn't able to follow exactly what you were explaining. Maybe showing some code would help. |
@stephenplusplus we changed it from an http code to a grpc code in the redesign, but it has exsisted for much longer than that. I wasn't sure if it had something to do with the old mechanism of automatically creating subscription names or something. |
Found the origin! googleapis/google-cloud-node#465 by @jonparrott. We used to have an option, |
We're not v1.0.0 yet, right? If we want, let's remove it. It's surprising. |
Adding a use case for clarity: Creating the same subscription |
I'm still a bit confused about the scenario reported in the first post. Would anyone be able to do an ELI5 on that for me? |
@stephenplusplus the client will seemingly allow the user to create two subscriptions that share the same name on different topics. Underneath the hood the client is saying "I've already got this resource you're good to go!" but the topic doesn't necessarily match what was passed into |
Could you show code that demonstrates the issue? |
const PubSub = require(`@google-cloud/pubsub`);
// Creates a client
const pubsub = new PubSub();
(async () => {
const subscriptionName = 'quix';
const fooTopic = 'foo';
const barTopic = 'bar';
await pubsub.createTopic(fooTopic);
await pubsub.createTopic(barTopic);
// Create a subsciption 'quix' on topic foo
const subscription1 = await pubsub.createSubscription(fooTopic, subscriptionName);
// Create a subsciption 'quix' on topic bar
// subscription2, despite being configured with a different topic returns successfully
const subscription2 = await pubsub.createSubscription(barTopic, subscriptionName);
})(); |
Thanks! In Pub/Sub, is it not possible to have a subscription with the same name on two |
Exactly- from what I've observed subscription names are unique across all topics. In the above scenario the client is swallowing the duplicate resource error and returning the existing subscription which makes you think the call was successful. |
The resource name of a subscription is unique, because its full name is a "path", like I ran the code you provided, and it exited successfully. To me, that is expected. Those topics should have been created without an error. When I ran it again, it errored: "Error: 6 ALREADY_EXISTS: Resource already exists in the project (resource=foo)." I believe that is expected as well, since it was trying to create something that already existed. |
The error isn't on the topic but the subscription. |
Could you elaborate? |
If you see a place where my line of thinking went wrong from my previous comment(s), please correct me! |
Apologies for the terse response! Here's a more detailed example illustrating the issue. From what I can tell subscriptions are unique by name (not topic). After running the code below I don't see an additional subscription for the second topic in the console. From cloud console: // Imports the Google Cloud client library
const PubSub = require(`@google-cloud/pubsub`);
// Creates a client
const pubsub = new PubSub();
(async () => {
const subscriptionName = 'quix';
const fooTopic = 'foo';
const barTopic = 'bar';
await pubsub.createTopic(fooTopic);
await pubsub.createTopic(barTopic);
// Create a subsciption 'quix' on topic foo
const subscription1 = await pubsub.createSubscription(fooTopic, subscriptionName);
// Create a subsciption 'quix' on topic bar
// subscription2, despite being configured with a different topic returns succesfully
const subscription2 = await pubsub.createSubscription(barTopic, subscriptionName);
// subscription1[0].on(`message`, (message) => {
// console.log('Subscriber 1, got message: ', message.data.toString());
// message.ack();
// });
subscription2[0].on(`message`, (message) => {
console.log('Subscriber 2, got message: ', message.data.toString());
message.ack();
});
pubsub
.topic(fooTopic)
.publisher()
.publish(new Buffer("foo!"));
pubsub
.topic(barTopic)
.publisher()
.publish(new Buffer("bar!"));
})(); Output:
|
Environment details
@google-cloud/pubsub
version: 0.18.0Steps to reproduce
foo
bar
quix
on topicfoo
quix
on topicbar
(this is successful?)If a subscription name already exists for a topic the client doesn't ensure it matches the same topic for the existing resource.
This check allows the subscription to appear to be created successfully despite <topic, name> pair not matching the original resource:
https://github.com/googleapis/nodejs-pubsub/blob/master/src/index.js#L249
Error caught internally:
Ideally
createSubscription
would fail when the topic name doesn't match the existing resource.The text was updated successfully, but these errors were encountered: