Error in zeromq self-connection
(Jinqing's column)
The server and client developed by zeromq message middleware do not need to be started in order. The client can be started before the server is enabled. This is a particularly useful feature of zmq. With this feature, the online game function servers can be restarted at will to enable automatic restart and continuous server upgrades.
In the traditional network connection mode, the processes that serve as internal servers in the online game server group must be restarted at the same time, otherwise the TCP connections between them will be disconnected. For example, the database proxy process is a service process, and all other processes are its client processes. Therefore, when the database proxy restarts, other processes also need to be restarted. The database proxy process must be started earlier than other processes. Without such order restrictions, the database proxy process can be restarted at will, and the service can be upgraded at any time without stopping services.
However, an error is also found. When a client process and a server process are on the same machine, if the service is not enabled, start the client process first. After a long period of time, you will find that the client process has established a connection with itself. The netstat display is as follows:
TCP 127.0.0.1: 34567 127.0.0.1: 34567 established
The local port number is the same as the remote port number, that is, the Service port. And then start the server process will fail because the port is occupied. The client will receive the data sent by itself.
This is because the client continuously uses random local ports to connect to the Service port, the connection fails, and the local port keeps changing until the local port is equal to the Service port. The above self-connection will be generated.
We have submitted a suggestion to disconnect the self-connection:
Https://zeromq.jira.com/browse/LIBZMQ-549
When the connection finds that the local port is equal to the Service port, it will be disconnected and the local port will be reconnected, so there will be no self-connection.
If the service process is on different machines, there will be no self-connection. Or the server can start up early. In addition, the random connection takes a long time, and the service is generally started before that.