chenBright commented on code in PR #3750:
URL: https://github.com/apache/brpc/pull/3750#discussion_r4585734613


##########
src/brpc/rdma/rdma_endpoint.cpp:
##########
@@ -2012,20 +2018,32 @@ int RdmaEndpoint::PollingModeInitialize(bthread_tag_t 
tag,
 
         return nullptr;
     };
-    for (int i = 0; i < FLAGS_rdma_poller_num; ++i) {
-        auto args = new FnArgs{&pollers[i], &running};
+    for (size_t i = 0; i < pollers.size(); ++i) {
+        std::unique_ptr<FnArgs> args(new FnArgs{&pollers[i], &running});
         auto attr = FLAGS_rdma_disable_bthread ? BTHREAD_ATTR_PTHREAD
                                                : BTHREAD_ATTR_NORMAL;
         attr.tag = tag;
         bthread_attr_set_name(&attr, "RdmaPolling");
         pollers[i].callback = callback;
         pollers[i].init_fn = init_fn;
         pollers[i].release_fn = release_fn;
-        auto rc = bthread_start_background(&pollers[i].tid, &attr, fn, args);
+#if defined(UNIT_TEST)
+        const int rc = g_start_rdma_poller_for_test(
+#else
+        const int rc = bthread_start_background(
+#endif
+            &pollers[i].tid, &attr, fn, args.get());
         if (rc != 0) {
-            LOG(ERROR) << "Fail to start rdma polling bthread";
+            running.store(false, std::memory_order_relaxed);
+            for (size_t j = 0; j < i; ++j) {
+                bthread_join(pollers[j].tid, nullptr);
+                pollers[j].tid = INVALID_BTHREAD;

Review Comment:
   Setting `running` to `false` before the old poller exits allows another 
initialization with the same tag to pass the entry CAS. Specifically, after A 
starts the first poller, creation of the second fails and A enters `join`. If B 
then initializes another Channel and sets `running` back to `true`, the old 
poller, which has not yet observed the stop signal, will continue running, and 
A's initialization will remain blocked. Initializations of different Channels 
share this `PollerGroup`, and the call chain has no serialization protection. 
Consider separating the stop signal from the initialization state to prevent 
the next batch of tasks from starting before rollback completes, and add a 
barrier-controlled concurrency test.



-- 
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]

Reply via email to