legionxiong opened a new pull request, #3406:
URL: https://github.com/apache/brpc/pull/3406
Make the handshake state atomic and publish RDMA_OFF before FALLBACK_TCP.
This prevents TCP event handling from observing a partially published fallback
state. Use a relaxed load for the completion-path check because it does not
consume related data.
### What problem does this PR solve?
Issue Number: #3405
Problem Summary:
`RdmaEndpoint::_state` is concurrently accessed by the RDMA handshake,
TCP event handling, and completion handling paths, but it is not atomic.
This causes a C++ data race.
In addition, `RdmaConnect::StartConnect()` publishes `FALLBACK_TCP`
before setting `RdmaTransport::_rdma_state` to `RDMA_OFF`. A concurrent
TCP event may therefore observe a partially published fallback state and
start TCP message processing while the transport still appears to use
RDMA.
### What is changed and the side effects?
Changed:
- Change `RdmaEndpoint::_state` to `butil::atomic<State>`.
- Set `RdmaTransport::_rdma_state` to `RDMA_OFF` before publishing
`RdmaEndpoint::_state` as `FALLBACK_TCP`.
- Use a relaxed atomic load for the `_state` check in
`RdmaEndpoint::HandleCompletion()`, because the check does not consume
data published by the state transition.
Side effects:
- Performance effects:
The handshake and TCP fallback paths use the default sequentially
consistent ordering. These paths are not hot after the handshake
completes. The completion hot path uses a relaxed load, so it does not
introduce unnecessary ordering overhead.
- Breaking backward compatibility:
None. This change does not modify any public API, wire protocol, or
externally visible behavior.
---
### Check List:
- Please make sure your changes are compilable.
- When providing us with a new feature, it is best to add related tests.
- Please follow [Contributor Covenant Code of
Conduct](https://github.com/apache/brpc/blob/master/CODE_OF_CONDUCT.md).
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]