samuel / go-thrift

A native Thrift package for Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

server does not close connection when client does

yancl opened this issue · comments

Hi, I notice that when some client fire a rpc request to server, then after receive the response and close the connection, the server just exits the goroutine for that connection, but does not close the connection. i know the gc will collect it for latter use,but i do not think it's good. i think it is just another kind of resource leak.
so i think add the following code in go-thrift/server.go can fix it:

func (c *serverCodec) Close() error {
c.transport.Close()
return nil
}

will you accept it? thanks:)

Also i look at net/http/server.go, it close the socket when a goroutine exits.

Thanks for catching that and raising the issue.

I don't know if it's much of a concern in the serverCodec since that should never really even get to Close(...) in most cases, and in clientCodec it would only become an issue when doing a lot of reconnects in a short time. However, it definitely makes sense to close the transport.

I added "return c.transport.Close()" to the Close() in both codecs.