diff --git a/src/core/lib/event_engine/posix_engine/posix_engine_listener.cc b/src/core/lib/event_engine/posix_engine/posix_engine_listener.cc index bb97756dc7c..07a4c99f966 100644 --- a/src/core/lib/event_engine/posix_engine/posix_engine_listener.cc +++ b/src/core/lib/event_engine/posix_engine/posix_engine_listener.cc @@ -182,11 +182,11 @@ void PosixEngineListenerImpl::AsyncConnectionAcceptor::NotifyOnAccept( } // For UNIX sockets, the accept call might not fill up the member - // sun_path of sockaddr_un, so explicitly call getsockname to get it. + // sun_path of sockaddr_un, so explicitly call getpeername to get it. if (addr.address()->sa_family == AF_UNIX) { socklen_t len = EventEngine::ResolvedAddress::MAX_SIZE_BYTES; - if (getsockname(fd, const_cast(addr.address()), &len) < 0) { - gpr_log(GPR_ERROR, "Closing acceptor. Failed getsockname: %s", + if (getpeername(fd, const_cast(addr.address()), &len) < 0) { + gpr_log(GPR_ERROR, "Closing acceptor. Failed getpeername: %s", strerror(errno)); close(fd); // Shutting down the acceptor. Unref the ref grabbed in diff --git a/src/core/lib/event_engine/posix_engine/posix_engine_listener.h b/src/core/lib/event_engine/posix_engine/posix_engine_listener.h index b24c2baad56..a10a7ee0583 100644 --- a/src/core/lib/event_engine/posix_engine/posix_engine_listener.h +++ b/src/core/lib/event_engine/posix_engine/posix_engine_listener.h @@ -110,6 +110,8 @@ class PosixEngineListenerImpl } ListenerSocketsContainer::ListenerSocket& Socket() { return socket_; } ~AsyncConnectionAcceptor() { + // If uds socket, unlink it so that the corresponding file is deleted. + UnlinkIfUnixDomainSocket(*socket_.sock.LocalAddress()); handle_->OrphanHandle(nullptr, nullptr, ""); delete notify_on_accept_; } diff --git a/src/core/lib/event_engine/tcp_socket_utils.cc b/src/core/lib/event_engine/tcp_socket_utils.cc index 9b4602d3e42..bc6f939556f 100644 --- a/src/core/lib/event_engine/tcp_socket_utils.cc +++ b/src/core/lib/event_engine/tcp_socket_utils.cc @@ -100,12 +100,11 @@ absl::StatusOr ResolvedAddrToUnixPathIfPossible( #else int len = resolved_addr->size() - sizeof(unix_addr->sun_family) - 1; #endif - bool abstract = (len < 0 || unix_addr->sun_path[0] == '\0'); + if (len <= 0) return ""; std::string path; - if (abstract) { - if (len >= 0) { - path = std::string(unix_addr->sun_path + 1, len); - } + if (unix_addr->sun_path[0] == '\0') { + // unix-abstract socket processing. + path = std::string(unix_addr->sun_path + 1, len); path = absl::StrCat(std::string(1, '\0'), path); } else { size_t maxlen = sizeof(unix_addr->sun_path); @@ -123,9 +122,9 @@ absl::StatusOr ResolvedAddrToUriUnixIfPossible( GRPC_RETURN_IF_ERROR(path.status()); std::string scheme; std::string path_string; - if (path->at(0) == '\0') { + if (!path->empty() && path->at(0) == '\0' && path->length() > 1) { scheme = "unix-abstract"; - path_string = path->length() > 1 ? path->substr(1, std::string::npos) : ""; + path_string = path->substr(1, std::string::npos); } else { scheme = "unix"; path_string = std::move(*path);