two-headBoy commented on code in PR #3595:
URL: https://github.com/apache/brpc/pull/3595#discussion_r4246986491
##########
src/brpc/socket.cpp:
##########
@@ -722,7 +722,10 @@ int Socket::Create(const SocketOptions& options, SocketId*
id) {
int Socket::OnCreated(const SocketOptions& options) {
if (_io_event.Init((void*)id()) != 0) {
LOG(ERROR) << "Fail to init IOEvent";
- SetFailed(ENOMEM, "%s", "Fail to init IOEvent");
+ // VersionedRefWithId::Create() performs the failure transition after
+ // OnCreated() returns an error; attach the user before returning so
+ // recycling invokes SocketUser::BeforeRecycle.
+ _user = options.user;
Review Comment:
Both valid, thanks. Fixed by no longer attaching`_user` on the failure path
at all:`_user = options.user` is moved to the very end of`OnCreated` , so it is
set only on the fully-constructed success path. No`OnCreated` failure (IOEvent
init,`bthread_id_create` ,`id_wait_list` init, or`get_resource` failing
before`OnCreated` runs) attaches the user, so recycling never
invokes`SocketUser::BeforeRecycle` on a failed create. This removes
the`EpollOutRequest` double-delete (`Connect` 's`delete req` becomes the sole
cleanup) and the re-entrant`_map_mutex` acquisition in`Acceptor::StartAccept` —
and incidentally the same latent hazards on the`bthread_id` /`id_wait_list`
failure sub-paths.
--
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]