'how to process tcp_check for golang tcp proxy

I write a tcp proxy with golang, for smtp and other protocols.

code like this:

ln,_:=net.Listen("tcp",":xx")
conn,_:=ln.Accept()
remoteConn,_:=net.Dial("tcp","xxx:xx")
go io.Copy(remoteConn,conn)
go io.Copy(conn,remoteConn)

It work fine, forward smtp message success.

a new question
When I deploy the proxy backend of LVS, the LVS send TCP_CHECK to proxy every second, When the proxy receives the request, it immediately establishes a connection to the remote server, but nothing data to write to.

Many nothing tcp connection to remote email server, it's very bad.

I tried :
Read all request data at first, if reqeust is TCP_CHECK, read will error(lvs send nothing to my proxy), then I know it's a TCP_CHECK request, it will not forward to remote email server.
But this is not work for smtp, Because the SMTP protocol interacts multiple times Something about smtp: https://www.smtp2go.com/blog/understanding-smtp-protocol/

Ask for help, any idea about how to process LVS's TCP_CHECK with golang?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source