diff --git a/common/mux/client.go b/common/mux/client.go index ebf73e09..6c9e90bc 100644 --- a/common/mux/client.go +++ b/common/mux/client.go @@ -296,7 +296,7 @@ func (m *ClientWorker) Dispatch(ctx context.Context, link *transport.Link) bool } sm := m.sessionManager - s := sm.Allocate(m.strategy) + s := sm.Allocate(&m.strategy) if s == nil { return false } diff --git a/common/mux/session.go b/common/mux/session.go index f5ca30a3..8bcb01bb 100644 --- a/common/mux/session.go +++ b/common/mux/session.go @@ -50,11 +50,12 @@ func (m *SessionManager) Count() int { return int(m.count) } -func (m *SessionManager) Allocate(Strategy ClientStrategy) *Session { - MaxConcurrency := int(Strategy.MaxConcurrency) - MaxConnection := uint16(Strategy.MaxConnection) +func (m *SessionManager) Allocate(Strategy *ClientStrategy) *Session { m.Lock() defer m.Unlock() + + MaxConcurrency := int(Strategy.MaxConcurrency) + MaxConnection := uint16(Strategy.MaxConnection) if m.closed || (MaxConcurrency > 0 && len(m.sessions) >= MaxConcurrency) || (MaxConnection > 0 && m.count >= MaxConnection) { return nil diff --git a/common/mux/session_test.go b/common/mux/session_test.go index 4c2ec189..a8491a9c 100644 --- a/common/mux/session_test.go +++ b/common/mux/session_test.go @@ -9,7 +9,7 @@ import ( func TestSessionManagerAdd(t *testing.T) { m := NewSessionManager() - s := m.Allocate(ClientStrategy{}) + s := m.Allocate(&ClientStrategy{}) if s.ID != 1 { t.Error("id: ", s.ID) } @@ -17,7 +17,7 @@ func TestSessionManagerAdd(t *testing.T) { t.Error("size: ", m.Size()) } - s = m.Allocate(ClientStrategy{}) + s = m.Allocate(&ClientStrategy{}) if s.ID != 2 { t.Error("id: ", s.ID) } @@ -39,7 +39,7 @@ func TestSessionManagerAdd(t *testing.T) { func TestSessionManagerClose(t *testing.T) { m := NewSessionManager() - s := m.Allocate(ClientStrategy{}) + s := m.Allocate(&ClientStrategy{}) if m.CloseIfNoSession() { t.Error("able to close")