-
Notifications
You must be signed in to change notification settings - Fork 4.5k
MUX: Refine and Fix some occasional problems #4861
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
这样可以省掉一把锁的样子 不会损失任何性能 |
we should also care about |
都是3没有问题 allocate是原子的 |
you should pass otherwise it is possible both goroutine use |
没看懂你在表达啥 use |
那就让它copy不就好了 反正这个值又不会变 是个常量 只会读而已 |
you are right, i just confused for a moment. anyway, there is no need to revert my last fix. |
i change I only added the minimum changes required, please check, thx. |
eb2b5bc
to
efe8179
Compare
I tested, if we don't close writer explicitly, it takes a few seconds to close the connection. but all sessions is closed and there is no data to send, so it is useless to wait before closing the connection. also, if /// also, returning |
This reverts commit 308f8a7.
Xray-core/common/mux/client.go
Lines 291 to 297 in cb1afb3
if this function run concurrent from two goroutine, some problems may arise, let explain why:
suppose
m.strategy.MaxConcurrency
is set to 4, and currently we have 3 sessions form.sessionManager
.suppose goroutine-A and goroutine-B run this function concurrency, because we have 3 sessions and
MaxCuncurrency
is set to 4,m.IsFull()
isfalse
for both goroutine, so both goroutine will runsm.Allocate()
.although
sessionManager
has it's own Lock, but it does not help in this situation, andsm.Allocate()
create a new session for each goroutine.so after running this two goroutine two new sessions created and the number of sessions reach to 5, but
MaxConcurrency
is set to 4, so we exceeded the value ofMaxConcurrency
!!!///
so we need another
sync.Mutex
lock for running this dispatch, to make sure we never exceed theMaxConcurrency
/MaxConnection
.also,
m.IsFull()
containm.Closed()
, so there is no need to check it again.