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][client] Memory leak during GET_LAST_MESSAGE_ID command processing. #301

Merged
merged 3 commits into from
Jul 25, 2023

Conversation

fundaev
Copy link
Contributor

@fundaev fundaev commented Jul 11, 2023

Motivation

ClientConnection::newGetLastMessageId method uses ClientConnection::sendRequestWithId one to send request. It adds a new node into ClientConnection::pendingRequests_ map. However ClientConnection::handleGetLastMessageIdResponse method does not affect this map. As a result the size of mentioned map is increased every time when Reader::getLastMessageIdAsync method is called.

Modifications

ClientConnection::newGetLastMessageId method uses ClientConnection::sendCommand one now to send request.

Verifying this change

This change is already covered by existing tests, such as ConsumerTest.testGetLastMessageId and ConsumerTest.testGetLastMessageIdBlockWhenConnectionDisconnected.

Documentation

  • doc-required
    (Your PR needs to update docs and you will update later)

  • [] doc-not-needed
    (Please explain why)

  • doc
    (Your PR contains doc changes)

  • doc-complete
    (Docs have been already added)

## Motivation
`ClientConnection::newGetLastMessageId` method uses `ClientConnection::sendRequestWithId` one to send request. It adds a new node into `ClientConnection::pendingRequests_` map. However `ClientConnection::handleGetLastMessageIdResponse` method does not affect this map. As a result the size of mentioned map is increased every time when `Reader::getLastMessageIdAsync` method is called.

## Modification
- `ClientConnection::newGetLastMessageId` method use now `ClientConnection::sendCommand` one to send request.
@Radrik5
Copy link

Radrik5 commented Jul 11, 2023

This change partially reverts commit 8735103 probably re-injecting timeout issue it fixed.

Copy link
Contributor

@BewareMyPower BewareMyPower left a comment

Choose a reason for hiding this comment

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

Just as @Radrik5 mentioned, it reverts the fix of apache/pulsar#12586.

I think a better solution is to remove the pendingGetLastMessageIdRequests_ map and remove it from pendingRequests_ in handleGetLastMessageIdResponse.

@BewareMyPower
Copy link
Contributor

BewareMyPower commented Jul 17, 2023

Could you address my comment? I will wait for some time. If not, I might open another PR to fix it since I'm going to cut the 3.3.0 release soon (maybe the next week)

@fundaev
Copy link
Contributor Author

fundaev commented Jul 17, 2023

Yes, I'll correct the solution soon. Sorry for the delay.

## Motivation
`ClientConnection::newGetLastMessageId` method uses `ClientConnection::sendRequestWithId` one to send request. It adds a new node into `ClientConnection::pendingRequests_` map. However `ClientConnection::handleGetLastMessageIdResponse` method does not affect this map. As a result the size of mentioned map is increased every time when `Reader::getLastMessageIdAsync` method is called.

## Modification
- `ClientConnection::newGetLastMessageId` method use now `ClientConnection::sendCommand` one to send request.
@fundaev
Copy link
Contributor Author

fundaev commented Jul 21, 2023

Sorry for late response.
Please look at the solution now. I left pendingGetLastMessageIdRequests_ cache. Otherwise it's necessary to return Future<Result, ResponseData> in ClientConnection::newGetLastMessageId. But the problem with timeout is fixed now too.

@BewareMyPower BewareMyPower added the bug Something isn't working label Jul 24, 2023
Copy link
Contributor

@BewareMyPower BewareMyPower left a comment

Choose a reason for hiding this comment

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

Please fix the code format

lib/GetLastMessageIdResponse.h Outdated Show resolved Hide resolved
@fundaev
Copy link
Contributor Author

fundaev commented Jul 24, 2023

Should I do anything else after your commit?

@BewareMyPower
Copy link
Contributor

Should I do anything else after your commit?

No

@BewareMyPower BewareMyPower added this to the 3.3.0 milestone Jul 25, 2023
@BewareMyPower BewareMyPower merged commit d1347c7 into apache:main Jul 25, 2023
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants