wwbmmm commented on code in PR #3767:
URL: https://github.com/apache/brpc/pull/3767#discussion_r4704516963


##########
src/brpc/server.cpp:
##########
@@ -1209,6 +1279,12 @@ int Server::StartInternal(const butil::EndPoint& 
endpoint,
         LOG(ERROR) << "Only IPv4 address supports port range feature";
         return -1;
     }
+    // Acceptors cache the protocol handlers built from ServerOptions, which 
may
+    // change between Start()s of the same Server, so rebuild them.
+    delete _am;
+    _am = nullptr;
+    delete _internal_am;
+    _internal_am = nullptr;

Review Comment:
   [replied by brpc-oncall robot] Removed the deletion. Acceptors are created 
once by the first `Start()` and are no longer destroyed when a stopped `Server` 
is restarted, so `GetStat()`/`SetMaxConnections()` can never observe a freed 
listener. A restart with a different `enabled_protocols` now fails with an 
error instead of reusing the stale handlers (test: 
`restart_rejects_changed_enabled_protocols`).



##########
src/brpc/server.cpp:
##########
@@ -1209,6 +1279,12 @@ int Server::StartInternal(const butil::EndPoint& 
endpoint,
         LOG(ERROR) << "Only IPv4 address supports port range feature";
         return -1;
     }
+    // Acceptors cache the protocol handlers built from ServerOptions, which 
may
+    // change between Start()s of the same Server, so rebuild them.
+    delete _am;
+    _am = nullptr;
+    delete _internal_am;
+    _internal_am = nullptr;

Review Comment:
   [replied by brpc-oncall robot] With the restart-time deletion removed, the 
acceptor is destroyed only by the `Server` destructor. On that path 
`StartAccept()` has no soft failure after `CloseIdleConnections` starts: the 
invalid-fd and force-ssl checks happen before it and a `Socket::Create()` 
failure is `LOG(FATAL)` (abort), so the cleanup thread cannot outlive the 
acceptor. No change is needed here; if you prefer, I can still make `Acceptor` 
stop the thread on any early return.



##########
src/brpc/server.cpp:
##########
@@ -1209,6 +1279,12 @@ int Server::StartInternal(const butil::EndPoint& 
endpoint,
         LOG(ERROR) << "Only IPv4 address supports port range feature";
         return -1;
     }
+    // Acceptors cache the protocol handlers built from ServerOptions, which 
may
+    // change between Start()s of the same Server, so rebuild them.
+    delete _am;
+    _am = nullptr;
+    delete _internal_am;
+    _internal_am = nullptr;

Review Comment:
   [replied by brpc-oncall robot] This window is pre-existing in `Acceptor` (it 
applies to the destructor path as well) and the withdrawn change was what made 
it reachable on restart: acceptors are no longer deleted at restart, so a 
restart can no longer free the listener while a pending `BeforeRecycle()` uses 
it. I did not restructure socket registration in the accept loop in this PR; 
that is an independent fix.



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