Skip to content

Conversation

@BewareMyPower
Copy link
Contributor

Motivation

We observed some logs that showed the handler instance is expired when the connection is established after a reconnection:

HandlerBase Weak reference is not valid anymore

LOG_DEBUG("HandlerBase Weak reference is not valid anymore");

Modifications

Pass a shared_ptr instead of a weak_ptr in HandlerBase::grabCnx to ensure the connectionOpened or connectionFailed callback is called if ClientImpl::getConnection is called. We only need to pass a weak_ptr in scheduleReconnection to skip the reconnection if the handler is expired.

### Motivation

We observed some logs that showed the handler instance is expired when
the connection is established after a reconnection:

```
HandlerBase Weak reference is not valid anymore
```

https://github.com/apache/pulsar-client-cpp/blob/b35ae1aa4b9834886c0889635de81834f9b2f774/lib/HandlerBase.cc#L92

### Modifications

Pass a `shared_ptr` instead of a `weak_ptr` in `HandlerBase::grabCnx` to
ensure the `connectionOpened` or `connectionFailed` callback is called
if `ClientImpl::getConnection` is called. We only need to pass a
`weak_ptr` in `scheduleReconnection` to skip the reconnection if the
handler is expired.
@BewareMyPower BewareMyPower added the bug Something isn't working label Oct 4, 2023
@BewareMyPower BewareMyPower added this to the 3.4.0 milestone Oct 4, 2023
@BewareMyPower BewareMyPower self-assigned this Oct 4, 2023
@merlimat merlimat merged commit af45a54 into apache:main Oct 4, 2023
merlimat pushed a commit to streamnative/pulsar-client-cpp that referenced this pull request Oct 4, 2023
apache#323)

We observed some logs that showed the handler instance is expired when
the connection is established after a reconnection:

```
HandlerBase Weak reference is not valid anymore
```

https://github.com/apache/pulsar-client-cpp/blob/b35ae1aa4b9834886c0889635de81834f9b2f774/lib/HandlerBase.cc#L92

Pass a `shared_ptr` instead of a `weak_ptr` in `HandlerBase::grabCnx` to
ensure the `connectionOpened` or `connectionFailed` callback is called
if `ClientImpl::getConnection` is called. We only need to pass a
`weak_ptr` in `scheduleReconnection` to skip the reconnection if the
handler is expired.
@BewareMyPower BewareMyPower deleted the bewaremypower/weak-handler-expired branch October 5, 2023 10:30
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.

2 participants