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


##########
test/brpc_rtmp_unittest.cpp:
##########
@@ -269,9 +269,13 @@ class PlayingDummyStream : public brpc::RtmpServerStream {
                       << " ms before responding play request";
             bthread_usleep(_sleep_ms * 1000L);
         }
+        // Keep the stream alive until the sender exits, even if a failed send
+        // synchronously runs OnStop() and releases the framework's references.
+        AddRefManually();
         int rc = bthread_start_background(&_play_thread, nullptr,
                                           RunSendData, this);
         if (rc) {
+            RemoveRefManually();
             status->set_error(rc, "Fail to create thread");
             return;
         }

Review Comment:
   fixed.



##########
test/brpc_rtmp_unittest.cpp:
##########
@@ -290,15 +294,22 @@ class PlayingDummyStream : public brpc::RtmpServerStream {
         LOG(INFO) << "OnStop of PlayingDummyStream=" << this;
         if (_state.exchange(STATE_STOPPED) == STATE_PLAYING) {
             bthread_stop(_play_thread);
-            bthread_join(_play_thread, nullptr);
+            // A send failure can invoke this callback in the sender itself.
+            // Its own reference keeps the stream alive until SendData returns.
+            if (_play_thread != bthread_self()) {
+                bthread_join(_play_thread, nullptr);
+            }
         }
     }
 
     void SendData();
     
 private:
     static void* RunSendData(void* arg) {
-        ((PlayingDummyStream*)arg)->SendData();
+        // Adopt the reference acquired before starting this bthread.
+        butil::intrusive_ptr<PlayingDummyStream> stream(
+            static_cast<PlayingDummyStream*>(arg), false);
+        stream->SendData();

Review Comment:
   fixed.



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