avoid DATA RACE on S3Options.localFilerSocket (#3571)

* avoid DATA RACE on S3Options.localFilerSocket
https://github.com/seaweedfs/seaweedfs/issues/3552

* copy localSocket
This commit is contained in:
Konstantin Lebedev 2022-09-01 22:33:23 +05:00 committed by GitHub
parent 90d55cd179
commit 8c3040db81
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 10 deletions

View file

@ -293,17 +293,18 @@ func (fo *FilerOptions) startFiler() {
httpS := &http.Server{Handler: defaultMux} httpS := &http.Server{Handler: defaultMux}
if runtime.GOOS != "windows" { if runtime.GOOS != "windows" {
if *fo.localSocket == "" { localSocket := *fo.localSocket
*fo.localSocket = fmt.Sprintf("/tmp/seaweefs-filer-%d.sock", *fo.port) if localSocket == "" {
localSocket = fmt.Sprintf("/tmp/seaweefs-filer-%d.sock", *fo.port)
} }
if err := os.Remove(*fo.localSocket); err != nil && !os.IsNotExist(err) { if err := os.Remove(localSocket); err != nil && !os.IsNotExist(err) {
glog.Fatalf("Failed to remove %s, error: %s", *fo.localSocket, err.Error()) glog.Fatalf("Failed to remove %s, error: %s", localSocket, err.Error())
} }
go func() { go func() {
// start on local unix socket // start on local unix socket
filerSocketListener, err := net.Listen("unix", *fo.localSocket) filerSocketListener, err := net.Listen("unix", localSocket)
if err != nil { if err != nil {
glog.Fatalf("Failed to listen on %s: %v", *fo.localSocket, err) glog.Fatalf("Failed to listen on %s: %v", localSocket, err)
} }
httpS.Serve(filerSocketListener) httpS.Serve(filerSocketListener)
}() }()

View file

@ -194,7 +194,7 @@ func (s3opt *S3Options) startS3Server() bool {
GrpcDialOption: grpcDialOption, GrpcDialOption: grpcDialOption,
AllowEmptyFolder: *s3opt.allowEmptyFolder, AllowEmptyFolder: *s3opt.allowEmptyFolder,
AllowDeleteBucketNotEmpty: *s3opt.allowDeleteBucketNotEmpty, AllowDeleteBucketNotEmpty: *s3opt.allowDeleteBucketNotEmpty,
LocalFilerSocket: s3opt.localFilerSocket, LocalFilerSocket: *s3opt.localFilerSocket,
DataCenter: *s3opt.dataCenter, DataCenter: *s3opt.dataCenter,
}) })
if s3ApiServer_err != nil { if s3ApiServer_err != nil {

View file

@ -28,7 +28,7 @@ type S3ApiServerOption struct {
GrpcDialOption grpc.DialOption GrpcDialOption grpc.DialOption
AllowEmptyFolder bool AllowEmptyFolder bool
AllowDeleteBucketNotEmpty bool AllowDeleteBucketNotEmpty bool
LocalFilerSocket *string LocalFilerSocket string
DataCenter string DataCenter string
} }
@ -59,7 +59,7 @@ func NewS3ApiServer(router *mux.Router, option *S3ApiServerOption) (s3ApiServer
filerGuard: security.NewGuard([]string{}, signingKey, expiresAfterSec, readSigningKey, readExpiresAfterSec), filerGuard: security.NewGuard([]string{}, signingKey, expiresAfterSec, readSigningKey, readExpiresAfterSec),
cb: NewCircuitBreaker(option), cb: NewCircuitBreaker(option),
} }
if option.LocalFilerSocket == nil || *option.LocalFilerSocket == "" { if option.LocalFilerSocket == "" {
s3ApiServer.client = &http.Client{Transport: &http.Transport{ s3ApiServer.client = &http.Client{Transport: &http.Transport{
MaxIdleConns: 1024, MaxIdleConns: 1024,
MaxIdleConnsPerHost: 1024, MaxIdleConnsPerHost: 1024,
@ -68,7 +68,7 @@ func NewS3ApiServer(router *mux.Router, option *S3ApiServerOption) (s3ApiServer
s3ApiServer.client = &http.Client{ s3ApiServer.client = &http.Client{
Transport: &http.Transport{ Transport: &http.Transport{
DialContext: func(_ context.Context, _, _ string) (net.Conn, error) { DialContext: func(_ context.Context, _, _ string) (net.Conn, error) {
return net.Dial("unix", *option.LocalFilerSocket) return net.Dial("unix", option.LocalFilerSocket)
}, },
}, },
} }