-
Notifications
You must be signed in to change notification settings - Fork 471
Make sshContext thread safe and fix the data race bug #211
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
Conversation
@wxiaoguang Could you please improve the commit message? What is the difference from #209? |
Done with a force push.
More details in #160 (comment) , IMO |
I suspect that this race was exposed by some change in the go1.21 compiler. These test failures appeared in the last 1-2 days for gitea and our CI did automatically upgrade to 1.21 when it went live. Never seen those before. |
Now it's the same as #209 ? |
No. #211 (comment)
Functions like |
But they are not thread-safe in this PR too. |
This one is safe, while that one isn't See the comment #160 (comment)
And this PR's description:
The struct:
|
And one more thing: changing a "ctx" field again and again is an anti-pattern of Golang design. So, it's good to make it immutable. |
Understand. With the original Go |
Nope, it ( Update: test has been added. |
Why use a list then if you replace the previous value? That's the same behaviour as a |
The reasons IMO are:
|
What behaviour are you talking about? The current implementation behaves like a map. The Go
|
The behavior:
For the GC, I do not see a real bad case for it. Go developers should seldom depend on this behavior.
For this project: Golang 1.12/1.13 |
Yes, that's the normal behaviour and would be identical with
That's sad |
Hmm, I think you are right for the map with |
@gustavosbarreto do you have more questions? |
LGTM |
Can you please squash the commits so we have a clean history without fix commits being applied on top of an original patch. |
Done, while IMO it's also good to do "squash" when the mergers are doing the final merge (into master), GitHub has that choice on the web UI, then contributors don't need to squash and the commit history is clear for reviewers. |
Kindly ping ~~~ |
@belak Can you please take a look into this? |
Kindly ping (2 weeks) ~~~ |
Kindly ping (another 2 weeks) ~~~ I don't like keeping stale PRs. If this PR doesn't get interest or this project is dead, I will close it. |
Hmm, another week, no interest. Close and feel free to take over. |
@wxiaoguang I apologize for the delay. I could have merged your PR, but I preferred to wait for other long-time contributors to approve it as well. Since no one has responded to my requests, I will proceed with the merge because I believe this fix is important. |
Sorry about the delay in reviewing - I forgot I set up a filter to put all Github PRs in a folder. Either way, this looks good to me - thanks for submitting it! |
Fix #160
The problem in old code, suppose there are 2 goroutines:
context.Context
interface functions ofsshCtx
, then it readssshCtx.Context
sshCtx.SetValue
, then it writessshCtx.Context
This PR makes the
sshCtx.Context
immutable, there won't be data race issue.The
Mutex.Lock/Unlock
is quite fast when there is no concurrency, it only callsatomic.CompareAndSwapInt32
/atomic.AddInt32
.