Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 12 Jul 2013 22:16:31 -0700
From:      trafdev <trafdev@mail.ru>
To:        freebsd-net@freebsd.org
Subject:   SO_REUSEPORT: strange kernel balancer behaviour
Message-ID:  <51E0E2AF.7090404@mail.ru>

next in thread | raw e-mail | index | archive | help
Hello.

Could someone help with following problem of SO_REUSEPORT.

Created server:

int sockd_acceptor_;
...

if ((sockd_acceptor_ = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
         LOG4CXX_ERROR_ERRNO(kLogger, "socket");
         return false;
     }
     struct sockaddr_in sa_in;
     memset(&sa_in, 0, sizeof(sa_in));
     sa_in.sin_family = AF_INET;
     sa_in.sin_port = htons(port);
     sa_in.sin_addr.s_addr = htonl(INADDR_ANY);
     int yes = 1;
     if (setsockopt(sockd_acceptor_, SOL_SOCKET, SO_REUSEPORT, &yes, 
sizeof (yes)) == -1) {
         LOG4CXX_ERROR_ERRNO(kLogger, "setsockopt");
         return false;
     }
     if (bind(sockd_acceptor_, (const struct sockaddr*)&sa_in, 
sizeof(sa_in)) == -1) {
         LOG4CXX_ERROR_ERRNO(kLogger, "bind");
         return false;
     }

     if (listen(sockd_acceptor_, listen_backlog) == -1) {
         LOG4CXX_ERROR_ERRNO(kLogger, "socket listen");
         return false;
     }
     if (!fcntl_set(sockd_acceptor_, O_NONBLOCK))
         return false;

Then libev is used as async dispatcher.

Server process 1 started, server process 2 started.
Everything is good so far, no bind errors.

Client started.

Server process 1 starts to reply, process 2 gets no requests yet.
This happens until process 1 is killed. Immediately after that process 2 
starts to respond (gets requests from client).

So it looks like there is a deque of processes sharing same port 
(SO_REUSEPORT) and only one process may respond.
Is this an expected behavior?



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?51E0E2AF.7090404>