You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "giokara-work (via GitHub)" <gi...@apache.org> on 2026/10/22 07:21:21 UTC
[PR] [Issue 1555][consumer] Release partition consumer resources after Unsubscribe [pulsar-client-go]
giokara-work opened a new pull request, #1556:
URL: https://github.com/apache/pulsar-client-go/pull/1556
Fixes #1555
### Motivation
When a partition consumer unsubscribes successfully, `internalUnsubscribe` sets its state to `consumerClosed` but never closes `closeCh`. `Close()` then returns early because the consumer is no longer `consumerReady`, so the events loop, the dispatcher (and its queued messages) and the ack grouping timer goroutine stay parked forever. `cancelFunc()` and `chunkedMsgCtxMap.Close()` are skipped as well. Any application that tears consumers down with Unsubscribe → Close leaks this set of resources for every partition. In our case that ended in OOMs at 125k–180k goroutines. Details are in #1555.
### Modifications
- After a successful unsubscribe, `unsubscribe()` runs the same teardown as `Close()`: it cancels the context, closes the ack grouping tracker and the chunked message map, and sends a close request to the events loop. The request is marked `unsubscribed`, so `internalClose` skips `CLOSE_CONSUMER` (the broker already removed the consumer). It still closes the compression providers and `closeCh`, so the events loop and the dispatcher exit.
- A failed unsubscribe still puts the consumer back to `consumerReady` and doesn't tear anything down, so `Close()` works as before.
- A later `Close()` is still a no-op for an unsubscribed consumer.
- Compression-provider cleanup is moved into `closeCompressionProviders()` so both close paths can share it.
Requests that are already queued behind the unsubscribe are drained before the close request, because the events loop handles them in order.
### Verifying this change
- [x] Make sure that the change passes the CI checks.
This change added tests and can be verified as follows:
- `TestUnsubscribeReleasesPartitionConsumer` (broker-free): unsubscribes a partition consumer whose events loop is running. It checks that `closeCh` is closed, the events loop exits, the context is cancelled, no `CLOSE_CONSUMER` is sent, and a later `Close()` doesn't block. It fails without this change.
- `TestConsumerUnsubscribeThenCloseReleasesGoroutines` (integration): runs subscribe → Unsubscribe → Close 20 times. It checks that each partition consumer's `closeCh` is closed and that the goroutine count stays near the baseline. It fails without this change.
- Measured with 100 subscribe → Unsubscribe → Close cycles: on master the goroutine count goes from 9 to 309 (3 per cycle). With this change it stays at 6.
- `make test_standalone` passes locally.
### Does this pull request potentially affect one of the following parts:
- Dependencies (does it add or upgrade a dependency): no
- The public API: no
- The schema: no
- The default values of configurations: no
- The wire protocol: no
### Documentation
- Does this pull request introduce a new feature? no
- If yes, how is the feature documented? not applicable
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Issue 1555][consumer] Release partition consumer resources after Unsubscribe [pulsar-client-go]
Posted by "nodece (via GitHub)" <gi...@apache.org>.
nodece merged PR #1556:
URL: https://github.com/apache/pulsar-client-go/pull/1556
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org