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

[Bug] Crash for regex consumer #359

Closed
1 of 2 tasks
astifter opened this issue Dec 1, 2023 · 1 comment · Fixed by #362
Closed
1 of 2 tasks

[Bug] Crash for regex consumer #359

astifter opened this issue Dec 1, 2023 · 1 comment · Fixed by #362

Comments

@astifter
Copy link
Contributor

astifter commented Dec 1, 2023

Search before asking

  • I searched in the issues and found nothing similar.

Version

3.3.0

Minimal reproduce step

Use regex subscription and simulate instable network connection.

What did you expect to see?

No crash.

What did you see instead?

Crash, see backtraces.
pulsar_crash.bt2.log
pulsar_crash.bt1.log

Anything else?

No response

Are you willing to submit a PR?

  • I'm willing to submit a PR!
@BewareMyPower
Copy link
Contributor

It seems a similar error with #358 that async_wait has been incorrectly used for many code references. I will push a fix soon.

@BewareMyPower BewareMyPower changed the title [Bug] [Bug] Crash for regex consumer Dec 4, 2023
BewareMyPower added a commit to BewareMyPower/pulsar-client-cpp that referenced this issue Dec 4, 2023
Fixes apache#358
Fixes apache#359

### Motivation

`async_wait` is not used correctly in some places. A callback that
captures the `this` pointer or reference to `this` is passed to
`async_wait`, if this object is destroyed when the callback is called,
an invalid memory access will happen.

### Modifications

Use the following pattern in all `async_wait` calls.

```c++
std::weak_ptr<T> weakSelf{shared_from_this()};
timer_->async_wait([weakSelf](/* ... */) {
    if (auto self = weakSelf.lock()) {
        self->foo();
    }
});
```
BewareMyPower added a commit to BewareMyPower/pulsar-client-cpp that referenced this issue Dec 4, 2023
Fixes apache#358
Fixes apache#359

### Motivation

`async_wait` is not used correctly in some places. A callback that
captures the `this` pointer or reference to `this` is passed to
`async_wait`, if this object is destroyed when the callback is called,
an invalid memory access will happen.

### Modifications

Use the following pattern in all `async_wait` calls.

```c++
std::weak_ptr<T> weakSelf{shared_from_this()};
timer_->async_wait([weakSelf](/* ... */) {
    if (auto self = weakSelf.lock()) {
        self->foo();
    }
});
```
BewareMyPower added a commit that referenced this issue Dec 6, 2023
Fixes #358
Fixes #359

### Motivation

`async_wait` is not used correctly in some places. A callback that
captures the `this` pointer or reference to `this` is passed to
`async_wait`, if this object is destroyed when the callback is called,
an invalid memory access will happen.

### Modifications

Use the following pattern in all `async_wait` calls.

```c++
std::weak_ptr<T> weakSelf{shared_from_this()};
timer_->async_wait([weakSelf](/* ... */) {
    if (auto self = weakSelf.lock()) {
        self->foo();
    }
});
```
BewareMyPower added a commit that referenced this issue Dec 6, 2023
Fixes #358
Fixes #359

### Motivation

`async_wait` is not used correctly in some places. A callback that
captures the `this` pointer or reference to `this` is passed to
`async_wait`, if this object is destroyed when the callback is called,
an invalid memory access will happen.

### Modifications

Use the following pattern in all `async_wait` calls.

```c++
std::weak_ptr<T> weakSelf{shared_from_this()};
timer_->async_wait([weakSelf](/* ... */) {
    if (auto self = weakSelf.lock()) {
        self->foo();
    }
});
```

(cherry picked from commit 24ab12c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants