-
Notifications
You must be signed in to change notification settings - Fork 235
Unhandled promises in Topic.flush and PubSub.close prevent proper shutdown #1463
Description
Both methods Topic.flush and PubSub.close indicate that it is ok to call them with no parameter and await their completion. Unfortunately when passing no callback, the function internals don't properly await and instead have unhandled promises which can in certain cases lead to message not being sent correctly.
This could be a reason to the recently observed increase in Total timeout of API google.pubsub.v1.Publisher exceeded 60000 milliseconds before any response was received. errors on Google Cloud Functions and Cloud Run because those runtime instances assumingly switch to idle before all messages have been send.
Take a look at Topic.flush:
Lines 193 to 199 in 38fba8b
| flush(): Promise<void>; | |
| flush(callback: EmptyCallback): void; | |
| flush(callback?: EmptyCallback): Promise<void> | void { | |
| // It doesn't matter here if callback is undefined; the Publisher | |
| // flush() will handle it. | |
| this.publisher.flush(callback!); | |
| } |
The call to this.publisher.flush(callback!); is not awaited nor returned so there is no way for the caller of Topic.flush to await the internal Promise completion without passing a callback.
Similar issue exists in PubSub.close.