-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
fix(transport): correctly release UDS locker file #2305
Conversation
return nil, err | ||
} | ||
ctx = context.WithValue(ctx, address, locker) | ||
// combine listener and unix domain socket locker | ||
defer func(locker *FileLocker) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
请换成更直观的写法(非 defer)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
改成了使用回调函数的方法
if s := strings.Split(address, ","); len(s) == 2 { | ||
address = s[0] | ||
perm, perr := strconv.ParseUint(s[1], 8, 32) | ||
if perr != nil { | ||
return nil, newError("failed to parse permission: " + s[1]).Base(perr) | ||
} | ||
|
||
defer func(file string, permission os.FileMode) { | ||
if err == nil { | ||
cerr := os.Chmod(address, permission) | ||
if cerr != nil { | ||
err = newError("failed to set permission for " + file).Base(cerr) | ||
} | ||
} | ||
}(address, os.FileMode(perm)) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
将逻辑移至常规 UDS 下,抽象 UDS 没有文件系统的权限概念。
感谢 PR,目测没有明显问题, |
* fix(transport): correctly release UDS locker file * use callback function to do some jobs after create listener
The unix domain socket locker file would not be released after closing listener.
That's because the context value set by the child cannot be obtained by the parent. And the current logic is a bit complex, we have to add the logic to release locker file everywhere we have used normal unix domain socket.