buptubuntu commented on a change in pull request #2497:
URL: https://github.com/apache/thrift/pull/2497#discussion_r781739700
##########
File path: lib/go/thrift/simple_server.go
##########
@@ -192,13 +195,27 @@ func (p *TSimpleServer) innerAccept() (int32, error) {
return 0, err
}
if client != nil {
- p.wg.Add(1)
+ ctx, cancel := context.WithCancel(context.Background())
+ p.wg.Add(2)
Review comment:
ctx cancel is done by close a chan
```golang
func (c *cancelCtx) cancel(removeFromParent bool, err error) {
if err == nil {
panic("context: internal error: missing cancel error")
}
c.mu.Lock()
if c.err != nil {
c.mu.Unlock()
return // already canceled
}
c.err = err
d, _ := c.done.Load().(chan struct{})
if d == nil {
c.done.Store(closedchan)
} else {
close(d)
}
for child := range c.children {
// NOTE: acquiring the child's lock while holding parent's lock.
child.cancel(false, err)
}
c.children = nil
c.mu.Unlock()
if removeFromParent {
removeChild(c.Context, c)
}
}
```
And yes, if the ctx is caneled, it will not close the inner channel again,
and will do nothing and return. So we still have to create a new ctx after stop
the server, because the ctx.Done() channel is already stopped.
divide p.wg.Add(2) into two p.wg.Add(1), it seems ok for now
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]