Skip to content

AutoUnsubscribe leaves ChanSubscription active #1890

Open
@faelys

Description

@faelys

Observed behavior

I hope I'm not using the library wrong (but if I am I would appreciate it being better documented), but AFAICT when calling AutoUnsubscribe on a ChanSubscription, the subscription remains active even after the delivery count is reached.

Visual inspection of nats.go from the git repository revealed that nc.removeSub is called only in:

  • waitForMsgs, which is started only for AsyncSubscriptions)
  • checkDrained, which is not started by AutoUnsubscribe because it sets drainMode to false
  • unsubscribe, when the unsubscription is immediate,
  • processNextMsgDelivered, which handles SyncSubscriptions.

So as far as I can tell, only ChanSubscription are never removed automatically, which is consistent with oldRequest needing to defer Unsubscribe after calling AutoUnsubscribe(1).

Expected behavior

I expected AutoUnsubscribe to be equivalent to Unsubscribe after the specified number of messages, which would change the subscription status to closed. That's what happens to AsyncSubscription, I expected ChanSubscription to behave similarly (or to see the documentation of AutoUnsuscribe mention the difference of behavior).

Server and client version

I witnessed it with nats.go v1.43.0, connecting to nats-server v2.10.23 (but I don't expect that to be relevant).

Host environment

All this runs on FreeBSD hosts on amd64 processors.

Steps to reproduce

Hopefully the explanations above are enough to consider the issue, but I can try writing a reproducer if it's really needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    defectSuspected defect such as a bug or regression

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions