1

My server program is running and I am trying to establish some TCP connections from redis client.

I am trying to establish 1150 client connections, and when I check netstat at server side I find a few "ESTABLISHED -" state where I don't understand the reason for the dash (-), omitting the program name.

At client side:

[root@smarak-2storage-testvnf-vm0 src]# ulimit -n
4096
[root@smarak-2storage-testvnf-vm0 src]# ./redis-benchmark -h 10.111.89.230 -p 6379 -c 1150 -t set -n 20000 -d 10000 -r 100000000000000 -I

At server side:

[root@sdl-blr-vm-1-14 src]# ulimit -n
1024
[root@sdl-blr-vm-1-14 src]# netstat -anp | grep -i 6379
tcp      129      0 0.0.0.0:6379            0.0.0.0:*               LISTEN      31535/respAccess
tcp        0      0 10.111.89.230:6379      10.111.89.112:34276     ESTABLISHED 31535/respAccess
tcp        0      0 10.111.89.230:6379      10.111.89.112:35048     ESTABLISHED -
tcp        0      0 10.111.89.230:6379      10.111.89.112:34614     ESTABLISHED 31535/respAccess
tcp        0      0 10.111.89.230:6379      10.111.89.112:34234     ESTABLISHED 31535/respAccess
tcp        0      0 10.111.89.230:6379      10.111.89.112:34984     ESTABLISHED 31535/respAccess
tcp        0      0 10.111.89.230:6379      10.111.89.112:34441     ESTABLISHED -
tcp        0      0 10.111.89.230:6379      10.111.89.112:34441     ESTABLISHED -
tcp        0      0 10.111.89.230:6379      10.111.89.112:34441     ESTABLISHED 
-

Why am I getting this ESTABLISHED - output? I think there are 1024 file descriptors at server side and hence as 1150 connections are initiated from client side, only 1024 connections should be established i.e "ESTABLISHED 31535/respAccess" as state (with program name) and others should be discarded. If there is a connection with state "ESTABLISHED", then why no program name attached to it?

2

Since you are using root account, you can see all processes of all users so - indicates that connection is handled by kernel.

In order to handle connection you have to call listen() function with socket descriptor and backlog parameters. According to man listen:

The backlog argument defines the maximum length to which the queue of pending connections for sockfd may grow. If a connection request arrives when the queue is full, the client may receive an error with an indication of ECONNREFUSED or, if the underlying protocol supports retransmission, the request may be ignored so that a later reattempt at connection succeeds.

The behavior of the backlog argument on TCP sockets changed with Linux 2.2. Now it specifies the queue length for completely established sockets waiting to be accepted, instead of the number of incomplete connection requests.

EDIT:
Incoming TCP connections are handled by kernel (TCP handshake), that's why you see connections as ESTABLISHED. When kernel establish TCP connection, connection is added to queue when it's waiting for program to be accepted. Backlog indicates size of the queue not maximum number of connections.

So '-' sign in netstat indicates that client requested connection to your server, kernel handled TCP handshake and added connection to queue, but connection have not yet been accepted by your server.

EDIT2:
Check out this website. There is cool flowchart which depicts entire process.

  • If they're not yet accepted can they be in state ESTABLISHED? – roaima Aug 22 '17 at 12:09
  • 1
    @roaima Because kernel establishes TCP handshake and adds new connection to queue. So from TCP perspective connection is ESTABLISHED (like documentation says: "it specifies the queue length for completely established sockets waiting to be accepted, instead of the number of incomplete connection requests") – mrc02_kr Aug 22 '17 at 13:12
  • Ah. I'm mis-reading. THanks for the clarification. +1 – roaima Aug 22 '17 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.