Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

socat return status code is 0 when listen timeout is passed #323603

Open
Bert-Proesmans opened this issue Jun 30, 2024 · 0 comments
Open

socat return status code is 0 when listen timeout is passed #323603

Bert-Proesmans opened this issue Jun 30, 2024 · 0 comments

Comments

@Bert-Proesmans
Copy link

Describe the bug

Socat's documentation states that when the listen timeout is reached, socat will return an error code.
I'm seeing return code 0 for VSOCK-LISTEN and TCP-LISTEN after timeout, which is incorrect.

Steps To Reproduce

Steps to reproduce the behavior:

  1. Run command socat -d4 TCP-LISTEN:22222,accept-timeout=1 /dev/null in shell with socat
  2. Verify return status behaviour with echo $?

Expected behavior

The value returned from step 2 should not be 0, but it is 0.

Additional context

click here to view socat debug output from my run
2024/06/30 14:30:40 socat[13611] D getpid()
2024/06/30 14:30:40 socat[13611] D getpid() -> 13611
2024/06/30 14:30:40 socat[13611] D setenv("SOCAT_PID", "13611", 1)
2024/06/30 14:30:40 socat[13611] D setenv() -> 0
2024/06/30 14:30:40 socat[13611] D setenv("SOCAT_PPID", "13611", 1)
2024/06/30 14:30:40 socat[13611] D setenv() -> 0
2024/06/30 14:30:40 socat[13611] I socat by Gerhard Rieger and contributors - see www.dest-unreach.org
2024/06/30 14:30:40 socat[13611] I This product includes software developed by the OpenSSL Project for use in the OpenSSL Toolkit. (http://www.openssl.org/)
2024/06/30 14:30:40 socat[13611] I This product includes software written by Tim Hudson ([email protected])
2024/06/30 14:30:40 socat[13611] D socat version 1.8.0.0 on 13 Nov 2023 19:31:09
2024/06/30 14:30:40 socat[13611] D setenv("SOCAT_VERSION", "1.8.0.0", 1)
2024/06/30 14:30:40 socat[13611] D setenv() -> 0
2024/06/30 14:30:40 socat[13611] D running on Linux version #1-NixOS SMP PREEMPT_DYNAMIC Thu May  2 14:32:50 UTC 2024, release 6.6.30, machine x86_64

2024/06/30 14:30:40 socat[13611] D argv[0]: "/nix/store/lxppfi8r56w5sjgvidsf9j5mi0584bak-socat-1.8.0.0/bin/socat"
2024/06/30 14:30:40 socat[13611] D argv[1]: "-d4"
2024/06/30 14:30:40 socat[13611] D argv[2]: "TCP-LISTEN:22222,accept-timeout=1"
2024/06/30 14:30:40 socat[13611] D argv[3]: "/dev/null"
2024/06/30 14:30:40 socat[13611] D sigaction(1, 0x7ffc3ab9b9e0, 0x0)
2024/06/30 14:30:40 socat[13611] D sigaction() -> 0
2024/06/30 14:30:40 socat[13611] D sigaction(2, 0x7ffc3ab9b9e0, 0x0)
2024/06/30 14:30:40 socat[13611] D sigaction() -> 0
2024/06/30 14:30:40 socat[13611] D sigaction(3, 0x7ffc3ab9b9e0, 0x0)
2024/06/30 14:30:40 socat[13611] D sigaction() -> 0
2024/06/30 14:30:40 socat[13611] D sigaction(4, 0x7ffc3ab9b9e0, 0x0)
2024/06/30 14:30:40 socat[13611] D sigaction() -> 0
2024/06/30 14:30:40 socat[13611] D sigaction(6, 0x7ffc3ab9b9e0, 0x0)
2024/06/30 14:30:40 socat[13611] D sigaction() -> 0
2024/06/30 14:30:40 socat[13611] D sigaction(7, 0x7ffc3ab9b9e0, 0x0)
2024/06/30 14:30:40 socat[13611] D sigaction() -> 0
2024/06/30 14:30:40 socat[13611] D sigaction(8, 0x7ffc3ab9b9e0, 0x0)
2024/06/30 14:30:40 socat[13611] D sigaction() -> 0
2024/06/30 14:30:40 socat[13611] D sigaction(11, 0x7ffc3ab9b9e0, 0x0)
2024/06/30 14:30:40 socat[13611] D sigaction() -> 0
2024/06/30 14:30:40 socat[13611] D sigaction(15, 0x7ffc3ab9b9e0, 0x0)
2024/06/30 14:30:40 socat[13611] D sigaction() -> 0
2024/06/30 14:30:40 socat[13611] D sigaction(10, 0x7ffc3ab9b9e0, 0x0)
2024/06/30 14:30:40 socat[13611] D sigaction() -> 0
2024/06/30 14:30:40 socat[13611] D signal(13, 0x1)
2024/06/30 14:30:40 socat[13611] D signal() -> 0x0
2024/06/30 14:30:40 socat[13611] D atexit(0x5591fd2de718)
2024/06/30 14:30:40 socat[13611] D atexit() -> 0
2024/06/30 14:30:40 socat[13611] D xioopen("TCP-LISTEN:22222,accept-timeout=1")
2024/06/30 14:30:40 socat[13611] D calloc(1, 928)
2024/06/30 14:30:40 socat[13611] D calloc() -> 0x5591febfbdb0
2024/06/30 14:30:40 socat[13611] D malloc(448)
2024/06/30 14:30:40 socat[13611] D malloc() -> 0x5591febfc1a0
2024/06/30 14:30:40 socat[13611] D getaddrinfo(NULL, "22222", {0x21,0,1,6,0,0x0,0x0,0x0}, 0x7ffc3ab9b4c0)
2024/06/30 14:30:40 socat[13611] D getaddrinfo(,,,{{AF=2 0.0.0.0:22222, }) -> 0
2024/06/30 14:30:40 socat[13611] D getaddrinfo() -> flags=0x21 family=2 socktype=1 protocol=6 addr=AF=2 0.0.0.0:22222
2024/06/30 14:30:40 socat[13611] D getaddrinfo() -> flags=0x21 family=10 socktype=1 protocol=6 addr=AF=10 [0000:0000:0000:0000:0000:0000:0000:0000]:22222
2024/06/30 14:30:40 socat[13611] I xioresolve(node="NULL", service="22222", ...): More than one address found
2024/06/30 14:30:40 socat[13611] D malloc(112)
2024/06/30 14:30:40 socat[13611] D malloc() -> 0x5591febfca40
2024/06/30 14:30:40 socat[13611] D socket(10, 1, 6)
2024/06/30 14:30:40 socat[13611] I socket(10, 1, 6) -> 5
2024/06/30 14:30:40 socat[13611] D fcntl(5, 2, 0x1)
2024/06/30 14:30:40 socat[13611] D fcntl() -> 0x0
2024/06/30 14:30:40 socat[13611] D setsockopt(5, 1, 2, {0x1}, 4)
2024/06/30 14:30:40 socat[13611] D setsockopt() -> 0
2024/06/30 14:30:40 socat[13611] D bind(5, AF=10 [0000:0000:0000:0000:0000:0000:0000:0000]:22222, 28)
2024/06/30 14:30:40 socat[13611] D bind() -> 0
2024/06/30 14:30:40 socat[13611] D listen(5, 5)
2024/06/30 14:30:40 socat[13611] D listen() -> 0
2024/06/30 14:30:40 socat[13611] D getsockname(5, 0x7ffc3ab9b5c0, 0x7ffc3ab9ad04{28})
2024/06/30 14:30:40 socat[13611] D getsockname(, {AF=10 [0000:0000:0000:0000:0000:0000:0000:0000]:22222}, {28}) -> 0
2024/06/30 14:30:40 socat[13611] I starting accept loop
2024/06/30 14:30:40 socat[13611] N listening on AF=10 [0000:0000:0000:0000:0000:0000:0000:0000]:22222
2024/06/30 14:30:40 socat[13611] D select(6, &0x20, &0x0, &0x0, &1.000000)
2024/06/30 14:30:41 socat[13611] D select -> (, 0x0, 0x0, 0x0, &0.000000), 0
2024/06/30 14:30:41 socat[13611] W accept: Connection timed out
2024/06/30 14:30:41 socat[13611] I close(5)
2024/06/30 14:30:41 socat[13611] D close()  -> 0
2024/06/30 14:30:41 socat[13611] N Waiting for child processes to terminate
2024/06/30 14:30:41 socat[13611] D sigaction(17, 0x7ffc3ab9aeb0, 0x0)
2024/06/30 14:30:41 socat[13611] D sigaction() -> 0
2024/06/30 14:30:41 socat[13611] D exit(0)
2024/06/30 14:30:41 socat[13611] D starting xioexit()
2024/06/30 14:30:41 socat[13611] I shutdown(5, 2)
2024/06/30 14:30:41 socat[13611] D shutdown()  -> -1
2024/06/30 14:30:41 socat[13611] I shutdown(5, 2): Bad file descriptor
2024/06/30 14:30:41 socat[13611] D finished xioexit()

Looking at file xio-listen.c:278-302, from latest release (tag tag-1.8.0.0), there is an exit(0) call after signalling child processes.
That looks like an upstream issue, but I'm gonna leave that triage to more experienced developers.

code fragment
int _xioopen_accept_fd(
	struct single *sfd,
	int xioflags,
	struct sockaddr *us,
	socklen_t uslen,
	struct opt *opts,
	int pf,
	int proto,
	int level)
{
// [...]
	    if (!FD_ISSET(sfd->fd, &rfd)) {
	       struct sigaction act;

	       Warn1("accept: %s", strerror(ETIMEDOUT));
	       Close(sfd->fd);
	       Notice("Waiting for child processes to terminate");
	       memset(&act, 0, sizeof(struct sigaction));
	       act.sa_flags   = SA_NOCLDSTOP/*|SA_RESTART*/
#ifdef SA_SIGINFO /* not on Linux 2.0(.33) */
		  |SA_SIGINFO
#endif
#ifdef SA_NOMASK
		  |SA_NOMASK
#endif
		  ;
#if HAVE_STRUCT_SIGACTION_SA_SIGACTION && defined(SA_SIGINFO)
	       act.sa_sigaction = 0;
#else /* Linux 2.0(.33) does not have sigaction.sa_sigaction */
	       act.sa_handler = 0;
#endif
	       sigemptyset(&act.sa_mask);
	       Sigaction(SIGCHLD, &act, NULL);
	       wait(NULL);
	       Exit(0);
	    }
	 }
// [...]
}

Notify maintainers

@edolstra, as package maintainer

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.6.30, NixOS, 24.05 (Uakari), 24.05.20240512.2057814`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.2`
 - nixpkgs: `/nix/store/vsbi6gfwf2bdamw0d0d9xndb1rrxfnbk-source`

Add a 👍 reaction to issues you find important.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant