net.Conn set 【SO_RCVBUF】, can‘t Close the Conn [golang]

  Kiến thức lập trình

goversion:go version go1.19.13 windows/amd64
hostarch:linux

fd, err := outConn.(*net.TCPConn).File() if err == nil { syscall.SetsockoptInt(int(fd.Fd()), syscall.SOL_SOCKET, syscall.SO_RCVBUF, 1024*128) }

Then, call the outConn.Close() returned nil error, but I used netstat to check the connection, and it was still in the ESTABLISH state. When I deleted the code that set the SO_RCVBUF size, everything returned to normal. I’m not sure what the problem is. Is there something wrong with my usage?
Of course, I can see the receive buffer has many bytes to read.

enter image description here

Please help me,thank you!!

I tried to close the same conn multiple times and received the error object returned by Close. If the error was not returned when closing for the first time, it was considered that the close was successful. When closing again, an error used the closed network (this is normal) would be reported.

When I tried to block the code that sets the BUF size, everything returned to normal.

Due to business needs, we set the SO_RCVBUF of the socket to 128k. I checked the information and said that if it is not set, the default buffer size under Linux is not set. The value on my machine is much larger than 128k, which is confusing.

New contributor

Nelo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT