Improve-worker (#7367)
* ♻️ refactor(worker): remove goto * ♻️ refactor(worker): let manager loop exit by itself * ♻️ refactor(worker): fix race condition when closing worker CloseSend is not safe to call when another goroutine concurrently calls Send. streamCancel already handles proper stream closure. Also, streamExit signal should be called AFTER sending shutdownMsg Now the worker has no race condition if stopped during any moment (hopefully, tested with -race flag) * 🐛 fix(task_logger): deadlock in log closure * 🐛 fix(balance): fix balance task Removes the outdated "UnloadVolume" step as it is handled by "DeleteVolume". #7346
This commit is contained in:
committed by
GitHub
parent
557aa4ec09
commit
f06ddd05cc
@@ -5,7 +5,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweedfs/weed/glog"
|
||||
@@ -26,7 +25,6 @@ type GrpcAdminClient struct {
|
||||
dialOption grpc.DialOption
|
||||
|
||||
cmds chan grpcCommand
|
||||
closeOnce sync.Once
|
||||
|
||||
// Reconnection parameters
|
||||
maxReconnectAttempts int
|
||||
@@ -103,12 +101,14 @@ func NewGrpcAdminClient(adminAddress string, workerID string, dialOption grpc.Di
|
||||
func (c *GrpcAdminClient) managerLoop() {
|
||||
state := &grpcState{shouldReconnect: true}
|
||||
|
||||
out:
|
||||
for cmd := range c.cmds {
|
||||
switch cmd.action {
|
||||
case ActionConnect:
|
||||
c.handleConnect(cmd, state)
|
||||
case ActionDisconnect:
|
||||
c.handleDisconnect(cmd, state)
|
||||
break out
|
||||
case ActionReconnect:
|
||||
if state.connected || state.reconnecting || !state.shouldReconnect {
|
||||
cmd.resp <- ErrAlreadyConnected
|
||||
@@ -240,9 +240,6 @@ func (c *GrpcAdminClient) reconnect(s *grpcState) error {
|
||||
if s.streamCancel != nil {
|
||||
s.streamCancel()
|
||||
}
|
||||
if s.stream != nil {
|
||||
s.stream.CloseSend()
|
||||
}
|
||||
if s.conn != nil {
|
||||
s.conn.Close()
|
||||
}
|
||||
@@ -412,9 +409,6 @@ func (c *GrpcAdminClient) Disconnect() error {
|
||||
resp: resp,
|
||||
}
|
||||
err := <-resp
|
||||
c.closeOnce.Do(func() {
|
||||
close(c.cmds)
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -427,9 +421,6 @@ func (c *GrpcAdminClient) handleDisconnect(cmd grpcCommand, s *grpcState) {
|
||||
// Send shutdown signal to stop reconnection loop
|
||||
close(s.reconnectStop)
|
||||
|
||||
// Send shutdown signal to stop handlers loop
|
||||
close(s.streamExit)
|
||||
|
||||
s.connected = false
|
||||
s.shouldReconnect = false
|
||||
|
||||
@@ -452,16 +443,14 @@ func (c *GrpcAdminClient) handleDisconnect(cmd grpcCommand, s *grpcState) {
|
||||
glog.Warningf("Failed to send shutdown message")
|
||||
}
|
||||
|
||||
// Send shutdown signal to stop handlers loop
|
||||
close(s.streamExit)
|
||||
|
||||
// Cancel stream context
|
||||
if s.streamCancel != nil {
|
||||
s.streamCancel()
|
||||
}
|
||||
|
||||
// Close stream
|
||||
if s.stream != nil {
|
||||
s.stream.CloseSend()
|
||||
}
|
||||
|
||||
// Close connection
|
||||
if s.conn != nil {
|
||||
s.conn.Close()
|
||||
|
||||
Reference in New Issue
Block a user