However, are there any other clever tools/methods to see if process listening on TCP port receives a message?
You can use strace
with -e trace=network
. This is what it prints on accepting a TCP connection, receiving an HTTP request, sending an HTTP response and closing the connection:
$ strace -v -f -e trace=network -p `cat logs/my_server.pid`
Process 2361 attached with 44 threads - interrupt to quit
[pid 2422] accept(11, {sa_family=AF_INET, sin_port=htons(56289), sin_addr=inet_addr("172.30.1.60")}, [16]) = 14
[pid 2422] getsockname(14, {sa_family=AF_INET, sin_port=htons(7754), sin_addr=inet_addr("172.30.1.60")}, [16]) = 0
[pid 2422] setsockopt(14, SOL_TCP, TCP_NODELAY, [1], 4) = 0
[pid 2422] setsockopt(14, SOL_SOCKET, SO_KEEPALIVE, [1], 4) = 0
[pid 2422] getsockopt(14, SOL_SOCKET, SO_OOBINLINE, [515004615020773376], [4]) = 0
[pid 2388] recvfrom(14, "GET /OPEN_", 10, MSG_PEEK, NULL, NULL) = 10
[pid 2388] recvfrom(14, "GET /OPEN_SESSION?LOGIN=HAS_ADMI"..., 4096, 0, NULL, NULL) = 246
[pid 2388] sendto(14, "HTTP/1.1 200 OK\r\nServer: MY_SER"..., 192, 0, NULL, 0) = 192
[pid 2388] sendto(14, "<?xml version='1.0' encoding = '"..., 680, 0, NULL, 0) = 680
[pid 2361] --- SIGIO (I/O possible) @ 0 (0) ---
[pid 2388] recvfrom(14, "", 4096, 0, NULL, NULL) = 0
[pid 2388] shutdown(14, 2 /* send and receive */) = 0
Based on your additional output, it appears that pywwetha is listening on port 80.
Stop it with:
systemctl stop pywwetha.service
and then disable it with:
systemctl disable pywwetha.service
and then try starting nginx after that.
Best Answer
The idea behind this is to ensure you don't receive packets targeted for the previous program listening on that port. This
TIME_WAIT
state is defined in RFC793 as two times the maximum segment lifetime.I don't know about other Operating Systems but I assume that all of these have some kind of similar behavior.
A workaround for this problem is to set
SO_REUSEADDR
on the socket which should ignore theTIME_WAIT
state.