mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-21 09:36:34 -05:00
fix a race condition issue in VMess inbound
This commit is contained in:
parent
bac9304e05
commit
20f046af0b
@ -18,6 +18,9 @@ func (this *VMessInboundHandler) generateCommand(request *protocol.RequestHeader
|
||||
|
||||
log.Info("VMessIn: Pick detour handler for port ", inboundHandler.Port(), " for ", availableMin, " minutes.")
|
||||
user := inboundHandler.GetUser(request.User.Email)
|
||||
if user == nil {
|
||||
return nil
|
||||
}
|
||||
return &protocol.CommandSwitchAccount{
|
||||
Port: inboundHandler.Port(),
|
||||
ID: user.Account.(*protocol.VMessAccount).ID.UUID(),
|
||||
|
@ -65,7 +65,7 @@ func (this *userByEmail) Get(email string) (*protocol.User, bool) {
|
||||
|
||||
// Inbound connection handler that handles messages in VMess format.
|
||||
type VMessInboundHandler struct {
|
||||
sync.Mutex
|
||||
sync.RWMutex
|
||||
packetDispatcher dispatcher.PacketDispatcher
|
||||
inboundHandlerManager proxyman.InboundHandlerManager
|
||||
clients protocol.UserValidator
|
||||
@ -93,6 +93,13 @@ func (this *VMessInboundHandler) Close() {
|
||||
}
|
||||
|
||||
func (this *VMessInboundHandler) GetUser(email string) *protocol.User {
|
||||
this.RLock()
|
||||
defer this.RUnlock()
|
||||
|
||||
if !this.accepting {
|
||||
return nil
|
||||
}
|
||||
|
||||
user, existing := this.usersByEmail.Get(email)
|
||||
if !existing {
|
||||
this.clients.Add(user)
|
||||
@ -120,16 +127,27 @@ func (this *VMessInboundHandler) Start() error {
|
||||
func (this *VMessInboundHandler) HandleConnection(connection internet.Connection) {
|
||||
defer connection.Close()
|
||||
|
||||
if !this.accepting {
|
||||
return
|
||||
}
|
||||
|
||||
connReader := v2net.NewTimeOutReader(8, connection)
|
||||
defer connReader.Release()
|
||||
|
||||
reader := v2io.NewBufferedReader(connReader)
|
||||
defer reader.Release()
|
||||
|
||||
this.RLock()
|
||||
if !this.accepting {
|
||||
this.RUnlock()
|
||||
return
|
||||
}
|
||||
session := raw.NewServerSession(this.clients)
|
||||
defer session.Release()
|
||||
|
||||
request, err := session.DecodeRequestHeader(reader)
|
||||
this.RUnlock()
|
||||
|
||||
if err != nil {
|
||||
if err != io.EOF {
|
||||
log.Access(connection.RemoteAddr(), "", log.AccessRejected, err)
|
||||
|
Loading…
Reference in New Issue
Block a user