Copilot commented on code in PR #3590:
URL: https://github.com/apache/brpc/pull/3590#discussion_r4236121788
##########
src/brpc/server.cpp:
##########
@@ -1370,6 +1374,30 @@ int Server::Join() {
return 0;
}
+void Server::DestroyPreStartAllocations() {
+ if (_status == RUNNING || _status == STOPPING) {
+ // Handled by Join().
+ return;
+ }
+ if (_keytable_pool != nullptr) {
+ // Keep the TLS key valid until its pooled data has been destroyed.
+ // Deleting the key first would disable DestroyServerTLS().
+ CHECK_EQ(0, bthread_keytable_pool_destroy(_keytable_pool));
+ // Same as Join(): don't delete the pool struct. Bthreads created
+ // with attr.keytable_pool == _keytable_pool may outlive
+ // the failed start and still call return_keytable() on exit. A
+ // destroyed pool makes them delete their KeyTables directly, but the
+ // struct itself must stay valid. The leak is annotated in
+ // StartInternal() and only happens on failed starts.
+ _keytable_pool = nullptr;
Review Comment:
This only nulls the pointer after `bthread_keytable_pool_destroy`; the
heap-allocated `bthread_keytable_pool_t` from `StartInternal()` is never
deleted. Consequently every failed `Start()` still leaks one pool object, so
repeated failures continue to grow memory even though the reserved `KeyTable`s
are reclaimed. If the pool must remain valid for outliving init bthreads, defer
freeing the struct until those bthreads exit (otherwise delete it when no
references remain).
This issue also appears on line 1396 of the same file.
--
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]