-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
enforce to close accepted connection after processing #2883
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -211,6 +211,10 @@ func (p *TSimpleServer) innerAccept() (int32, error) { | |
select { | ||
case <-ctx.Done(): | ||
// client exited, do nothing | ||
if client != nil { | ||
client.Close() | ||
client = nil | ||
} | ||
case <-p.stopChan: | ||
// TSimpleServer.Close called, close the client connection | ||
client.Close() | ||
|
@@ -270,6 +274,7 @@ func (p *TSimpleServer) Stop() error { | |
} | ||
|
||
<-ctx.Done() | ||
p.stopChan = nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this does nothing, it's immediately overwritten by the next line |
||
p.stopChan = make(chan struct{}) | ||
return nil | ||
} | ||
|
@@ -356,6 +361,7 @@ func (p *TSimpleServer) processRequests(client TTransport) (err error) { | |
ok, err := processor.Process(ctx, inputProtocol, outputProtocol) | ||
if errors.Is(err, ErrAbandonRequest) { | ||
err := client.Close() | ||
client = nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this does not work as you expected. here the whole nil checking regarding client is also unnecessary, if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense. Then is it good to have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer to defer it in |
||
if errors.Is(err, net.ErrClosed) { | ||
// In this case, it's kinda expected to get | ||
// net.ErrClosed, treat that as no-error | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you explain more why do we need to close the client here? is there any connection leak otherwise?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, if the call to Close is not called, then any dynamically allocated data in client object is lost forever and hence the caller's golang runtime keeps eating memory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would that affect overall performance, e.g. when doing multiple calls?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you help clarify what is your overall performance concern?
Below is my understanding of how the simpleServer works with its serverTransport regarding accept an incoming request. Please correct me if I miss anything.
A client object is created by calling the underlying serverTransport.Accept(). I think client.Close() is to signal serverTransport that thrift server has finished using this client. So serverTransport could do whatever is required on its part, either to cleanup or recycle the object for reuse.
Without the signal from thrift server, what is expected from serverTransport to manage client object created by itself? The reference to client is lost after processing the request.
I guess thrift simple server has some assumption on how serverTransport to manage client created by serverTransport itself. Could you help advise where I could find the assumption? Or help explain the choice why not to enforce close client after processing.
Thanks for helping to review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I simply asked a question. If your answer is a validated "No it will not affect perf because ..." that's fine with me.