aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Lebedev <9497591+kmlebedev@users.noreply.github.com>2022-09-01 22:33:23 +0500
committerGitHub <noreply@github.com>2022-09-01 10:33:23 -0700
commit8c3040db81ac3c3a5b80d675ba3cf044420d4b9a (patch)
tree123184c7635b1f578884c5ec5d0e4c64f8122e64
parent90d55cd179732a375f112c72893e2cca1b41afd1 (diff)
downloadseaweedfs-8c3040db81ac3c3a5b80d675ba3cf044420d4b9a.tar.xz
seaweedfs-8c3040db81ac3c3a5b80d675ba3cf044420d4b9a.zip
avoid DATA RACE on S3Options.localFilerSocket (#3571)
* avoid DATA RACE on S3Options.localFilerSocket https://github.com/seaweedfs/seaweedfs/issues/3552 * copy localSocket
-rw-r--r--weed/command/filer.go13
-rw-r--r--weed/command/s3.go2
-rw-r--r--weed/s3api/s3api_server.go6
3 files changed, 11 insertions, 10 deletions
diff --git a/weed/command/filer.go b/weed/command/filer.go
index 0dd35e5bd..452e76228 100644
--- a/weed/command/filer.go
+++ b/weed/command/filer.go
@@ -293,17 +293,18 @@ func (fo *FilerOptions) startFiler() {
httpS := &http.Server{Handler: defaultMux}
if runtime.GOOS != "windows" {
- if *fo.localSocket == "" {
- *fo.localSocket = fmt.Sprintf("/tmp/seaweefs-filer-%d.sock", *fo.port)
+ localSocket := *fo.localSocket
+ if localSocket == "" {
+ localSocket = fmt.Sprintf("/tmp/seaweefs-filer-%d.sock", *fo.port)
}
- if err := os.Remove(*fo.localSocket); err != nil && !os.IsNotExist(err) {
- glog.Fatalf("Failed to remove %s, error: %s", *fo.localSocket, err.Error())
+ if err := os.Remove(localSocket); err != nil && !os.IsNotExist(err) {
+ glog.Fatalf("Failed to remove %s, error: %s", localSocket, err.Error())
}
go func() {
// start on local unix socket
- filerSocketListener, err := net.Listen("unix", *fo.localSocket)
+ filerSocketListener, err := net.Listen("unix", localSocket)
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)
}()
diff --git a/weed/command/s3.go b/weed/command/s3.go
index 4bcb9527b..d69ac214c 100644
--- a/weed/command/s3.go
+++ b/weed/command/s3.go
@@ -194,7 +194,7 @@ func (s3opt *S3Options) startS3Server() bool {
GrpcDialOption: grpcDialOption,
AllowEmptyFolder: *s3opt.allowEmptyFolder,
AllowDeleteBucketNotEmpty: *s3opt.allowDeleteBucketNotEmpty,
- LocalFilerSocket: s3opt.localFilerSocket,
+ LocalFilerSocket: *s3opt.localFilerSocket,
DataCenter: *s3opt.dataCenter,
})
if s3ApiServer_err != nil {
diff --git a/weed/s3api/s3api_server.go b/weed/s3api/s3api_server.go
index 31ee1dc92..76163d724 100644
--- a/weed/s3api/s3api_server.go
+++ b/weed/s3api/s3api_server.go
@@ -28,7 +28,7 @@ type S3ApiServerOption struct {
GrpcDialOption grpc.DialOption
AllowEmptyFolder bool
AllowDeleteBucketNotEmpty bool
- LocalFilerSocket *string
+ LocalFilerSocket string
DataCenter string
}
@@ -59,7 +59,7 @@ func NewS3ApiServer(router *mux.Router, option *S3ApiServerOption) (s3ApiServer
filerGuard: security.NewGuard([]string{}, signingKey, expiresAfterSec, readSigningKey, readExpiresAfterSec),
cb: NewCircuitBreaker(option),
}
- if option.LocalFilerSocket == nil || *option.LocalFilerSocket == "" {
+ if option.LocalFilerSocket == "" {
s3ApiServer.client = &http.Client{Transport: &http.Transport{
MaxIdleConns: 1024,
MaxIdleConnsPerHost: 1024,
@@ -68,7 +68,7 @@ func NewS3ApiServer(router *mux.Router, option *S3ApiServerOption) (s3ApiServer
s3ApiServer.client = &http.Client{
Transport: &http.Transport{
DialContext: func(_ context.Context, _, _ string) (net.Conn, error) {
- return net.Dial("unix", *option.LocalFilerSocket)
+ return net.Dial("unix", option.LocalFilerSocket)
},
},
}