Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 3 additions & 8 deletions lib/go/thrift/simple_server.go
Expand Up @@ -24,7 +24,6 @@ import (
"errors"
"fmt"
"io"
"net"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -195,12 +194,14 @@ func (p *TSimpleServer) innerAccept() (int32, error) {
return 0, err
}
if client != nil {

ctx, cancel := context.WithCancel(context.Background())
p.wg.Add(2)

go func() {
defer p.wg.Done()
defer cancel()
defer client.Close()
if err := p.processRequests(client); err != nil {
p.logger(fmt.Sprintf("error processing request: %v", err))
}
Expand Down Expand Up @@ -355,13 +356,7 @@ func (p *TSimpleServer) processRequests(client TTransport) (err error) {

ok, err := processor.Process(ctx, inputProtocol, outputProtocol)
if errors.Is(err, ErrAbandonRequest) {
err := client.Close()
if errors.Is(err, net.ErrClosed) {
// In this case, it's kinda expected to get
// net.ErrClosed, treat that as no-error
return nil
}
return err
return nil
}
if errors.As(err, new(TTransportException)) && err != nil {
return err
Expand Down