From 910511e5dcd84e0f8bea5e3cb4da2965e19e39cd Mon Sep 17 00:00:00 2001 From: Kansho Nishida Date: Thu, 4 Jul 2019 15:18:48 +0900 Subject: dumpstate: set backlog to zero Set backlog to 0 to make sure that queue size will be minimum. In Linux, because the minimum queue will be 1, connect() will be blocked if the other clients already called connect() and the connection request was not accepted. Bug: 123306389 Bug: 135575100 Test: execute bugreport in parallel Change-Id: Iee94de88deb82746818b729387ed9cd39e9b2f99 Signed-off-by: Kansho Nishida --- cmds/dumpstate/utils.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'cmds/dumpstate/utils.cpp') diff --git a/cmds/dumpstate/utils.cpp b/cmds/dumpstate/utils.cpp index 4cbf5776d3..e08c80627c 100644 --- a/cmds/dumpstate/utils.cpp +++ b/cmds/dumpstate/utils.cpp @@ -725,7 +725,11 @@ int open_socket(const char *service) { return -1; } fcntl(s, F_SETFD, FD_CLOEXEC); - if (listen(s, 4) < 0) { + + // Set backlog to 0 to make sure that queue size will be minimum. + // In Linux, because the minimum queue will be 1, connect() will be blocked + // if the other clients already called connect() and the connection request was not accepted. + if (listen(s, 0) < 0) { MYLOGE("listen(control socket): %s\n", strerror(errno)); return -1; } @@ -736,6 +740,9 @@ int open_socket(const char *service) { // Close socket just after accept(), to make sure that connect() by client will get error // when the socket is used by the other services. + // There is still a race condition possibility between accept and close, but there is no way + // to close-on-accept atomically. + // See detail; b/123306389#comment25 close(s); if (fd < 0) { -- cgit v1.2.3-59-g8ed1b