Skip to content

Instantly share code, notes, and snippets.

@Soulou Soulou/Client output
Created Dec 27, 2014

Embed
What would you like to do?
go-graceful-restart - netstat
└> go run pong.go
[Client] Received 4 bytes, 'ping'
[Client] Sent 'ping'
[Client] Received 4 bytes, 'ping'
[Client] Sent 'ping'
...
└> go run ./pong.go
[Client] Received 4 bytes, 'ping'
[Client] Sent 'ping'
[Client] Received 4 bytes, 'ping'
[Client] Sent 'ping'
...
# server and 1 client
tcp 0 0 127.0.0.1:51675 127.0.0.1:12345 ESTABLISHED 22564/pong
tcp6 0 0 :::12345 :::* LISTEN 22426/./go-graceful
tcp6 0 0 127.0.0.1:12345 127.0.0.1:51675 ESTABLISHED 22426/./go-graceful
# after SIGHUP (the same)
tcp 0 0 127.0.0.1:51675 127.0.0.1:12345 ESTABLISHED 22564/pong
tcp6 0 0 :::12345 :::* LISTEN 22426/./go-graceful
tcp6 0 0 127.0.0.1:12345 127.0.0.1:51675 ESTABLISHED 22426/./go-graceful
# 2 servers and 2 clients (new client is connect to the same socket which is still associated to first server)
tcp 0 0 127.0.0.1:51702 127.0.0.1:12345 ESTABLISHED 22839/pong
tcp 0 0 127.0.0.1:51675 127.0.0.1:12345 ESTABLISHED 22564/pong
tcp6 0 0 :::12345 :::* LISTEN 22426/./go-graceful
tcp6 0 0 127.0.0.1:12345 127.0.0.1:51675 ESTABLISHED 22426/./go-graceful
tcp6 0 0 127.0.0.1:12345 127.0.0.1:51702 ESTABLISHED 22682/./go-graceful
# end of 1st client/server (netstat finally got that the socket has been passed)
tcp 0 0 127.0.0.1:51702 127.0.0.1:12345 ESTABLISHED 22839/pong
tcp6 0 0 :::12345 :::* LISTEN 22682/./go-graceful
tcp6 0 0 127.0.0.1:12345 127.0.0.1:51702 ESTABLISHED 22682/./go-graceful
└> ./go-graceful-restart-example
# Start server and one client
2014/12/27 13:56:12 [Server - 22426] Listen on [::]:12345
2014/12/27 13:56:28 [Server - 22426] [Server] Sent 'ping'
2014/12/27 13:56:28 [Server - 22426] [Server] OK: read 4 bytes: 'pong'
2014/12/27 13:56:29 [Server - 22426] [Server] Sent 'ping'
2014/12/27 13:56:29 [Server - 22426] [Server] OK: read 4 bytes: 'pong'
2014/12/27 13:56:30 [Server - 22426] [Server] Sent 'ping'
2014/12/27 13:56:30 [Server - 22426] [Server] OK: read 4 bytes: 'pong'
...
# Sending SIGHUP to 22426, 22682 starts
2014/12/27 13:56:56 [Server - 22426] Stop accepting connections
2014/12/27 13:56:56 [Server - 22426] SIGHUP received: fork-exec to 22682
2014/12/27 13:56:56 [Server - 22682] Listen on [::]:12345
2014/12/27 13:56:56 [Server - 22426] [Server] Sent 'ping'
2014/12/27 13:56:56 [Server - 22426] [Server] OK: read 4 bytes: 'pong'
2014/12/27 13:56:57 [Server - 22426] [Server] Sent 'ping'
2014/12/27 13:56:57 [Server - 22426] [Server] OK: read 4 bytes: 'pong'
2014/12/27 13:56:58 [Server - 22426] [Server] Sent 'ping'
...
# New client: new server is answering while the old one is still running
2014/12/27 13:57:20 [Server - 22682] [Server] Sent 'ping'
2014/12/27 13:57:20 [Server - 22682] [Server] OK: read 4 bytes: 'pong'
2014/12/27 13:57:20 [Server - 22426] [Server] Sent 'ping'
2014/12/27 13:57:20 [Server - 22426] [Server] OK: read 4 bytes: 'pong'
2014/12/27 13:57:21 [Server - 22682] [Server] Sent 'ping'
2014/12/27 13:57:21 [Server - 22682] [Server] OK: read 4 bytes: 'pong'
2014/12/27 13:57:21 [Server - 22426] [Server] Sent 'ping'
2014/12/27 13:57:21 [Server - 22426] [Server] OK: read 4 bytes: 'pong'
2014/12/27 13:57:22 [Server - 22682] [Server] Sent 'ping'
2014/12/27 13:57:22 [Server - 22682] [Server] OK: read 4 bytes: 'pong'
...
# Stop first client, first server stops correctly.
2014/12/27 13:57:36 [Server - 22426] [Server] OK: read 4 bytes: 'pong'
2014/12/27 13:57:37 [Server - 22426] [Server] Sent 'ping'
2014/12/27 13:57:37 [Server - 22426] [Server] OK: read 4 bytes: 'pong'
2014/12/27 13:57:38 [Server - 22426] [Server] Sent 'ping'
2014/12/27 13:57:38 [Server - 22426] [Error] fail to read from socket: EOF
2014/12/27 13:57:38 [Server - 22426] 22426 Server gracefully shutdown
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.