Skip to content

Pub/Sub - Nack messages on drop of handler #4514

@dbolduc

Description

@dbolduc

The Handler has a fn ack(self) and a fn nack(self). If the application drops the handler without calling either, we continue to hold the message in lease management, and continue to extend its lease, even though it can never be acknowledged by the application.

We should nack messages on drop. And we should consider just getting rid of h.nack(), when we can drop(h) instead.


To implement this, we will want to hold an inner state in an option1. Something like:

struct AtLeastOnce {
  inner: Option<AtLeastOnceImpl>;
}

impl AtLeastOnce {
  fn ack(self) {
    if let Some(inner) = std::mem::take(self.inner) {
      inner.ack(); // or whatever.
    }
  }
}

impl Drop for AtLeastOnce {
  fn drop(&mut self) {
    if let Some(inner) = std::mem::take(self.inner) {
      inner.nack(); // or whatever.
    }
  }
}

Footnotes

  1. We cannot consume self for structs that have a manual drop. Unless we are willing to be unsafe.

Metadata

Metadata

Assignees

Labels

api: pubsubIssues related to the Pub/Sub API.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions