Skip to content
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

Fix semaphore and memory leak when chunks failed to enqueue #13454

Conversation

BewareMyPower
Copy link
Contributor

Motivation

When a large message is sent by chunks, each chunk needs to reserve a spot of the semaphore. However, when it failed, the already reserved memory from limiter and spots from semaphore are not released.

Modifications

  • Release the semaphore and memory when canEnqueueRequest returns false for chunks.
  • Add testChunksEnqueueFailed to cover this case. It sends a large message whose number of chunks is greater than the maxPendingMessages so that the first time canEnqueueRequest returns true while the following canEnqueueRequest calls will return false.

Verifying this change

  • Make sure that the change passes the CI checks.

This change added tests testChunksEnqueueFailed.

@BewareMyPower BewareMyPower added type/bug The PR fixed a bug or issue reported a bug area/client doc-not-needed Your PR changes do not impact docs release/2.8.3 release/2.9.2 labels Dec 22, 2021
@BewareMyPower BewareMyPower added this to the 2.10.0 milestone Dec 22, 2021
@BewareMyPower BewareMyPower self-assigned this Dec 22, 2021
Copy link
Contributor

@codelipenghui codelipenghui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

Copy link
Contributor

@Jason918 Jason918 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@BewareMyPower BewareMyPower merged commit 2e2cd57 into apache:master Dec 24, 2021
@BewareMyPower BewareMyPower deleted the bewaremypower/fix-producer-limiter-leak branch December 24, 2021 02:56
Technoboy- pushed a commit to Technoboy-/pulsar that referenced this pull request Dec 29, 2021
…3454)

### Motivation

When a large message is sent by chunks, each chunk needs to reserve a spot of the semaphore. However, when it failed, the already reserved memory from limiter and spots from semaphore are not released.

### Modifications

- Release the semaphore and memory when `canEnqueueRequest` returns false for chunks.
- Add `testChunksEnqueueFailed` to cover this case. It sends a large message whose number of chunks is greater than the `maxPendingMessages` so that the first time `canEnqueueRequest` returns true while the following `canEnqueueRequest` calls will return false.
codelipenghui pushed a commit that referenced this pull request Dec 30, 2021
### Motivation

When a large message is sent by chunks, each chunk needs to reserve a spot of the semaphore. However, when it failed, the already reserved memory from limiter and spots from semaphore are not released.

### Modifications

- Release the semaphore and memory when `canEnqueueRequest` returns false for chunks.
- Add `testChunksEnqueueFailed` to cover this case. It sends a large message whose number of chunks is greater than the `maxPendingMessages` so that the first time `canEnqueueRequest` returns true while the following `canEnqueueRequest` calls will return false.

(cherry picked from commit 2e2cd57)
@codelipenghui codelipenghui added the cherry-picked/branch-2.9 Archived: 2.9 is end of life label Dec 30, 2021
codelipenghui pushed a commit that referenced this pull request Dec 30, 2021
### Motivation

When a large message is sent by chunks, each chunk needs to reserve a spot of the semaphore. However, when it failed, the already reserved memory from limiter and spots from semaphore are not released.

### Modifications

- Release the semaphore and memory when `canEnqueueRequest` returns false for chunks.
- Add `testChunksEnqueueFailed` to cover this case. It sends a large message whose number of chunks is greater than the `maxPendingMessages` so that the first time `canEnqueueRequest` returns true while the following `canEnqueueRequest` calls will return false.

(cherry picked from commit 2e2cd57)
@codelipenghui codelipenghui added the cherry-picked/branch-2.8 Archived: 2.8 is end of life label Dec 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/client cherry-picked/branch-2.8 Archived: 2.8 is end of life cherry-picked/branch-2.9 Archived: 2.9 is end of life doc-not-needed Your PR changes do not impact docs release/2.8.3 release/2.9.2 type/bug The PR fixed a bug or issue reported a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants