mirror of https://github.com/XTLS/Xray-core
Add mutex for vmess auth writer
Mutex is needed as we removed pipe in mux server. The conn writer need to be guarded when multiple sub-connection writing back responses.pipe
parent
e188993d4a
commit
4eadb8ff64
|
@ -4,6 +4,7 @@ import (
|
||||||
"crypto/cipher"
|
"crypto/cipher"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"io"
|
"io"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/xtls/xray-core/common"
|
"github.com/xtls/xray-core/common"
|
||||||
"github.com/xtls/xray-core/common/buf"
|
"github.com/xtls/xray-core/common/buf"
|
||||||
|
@ -231,6 +232,7 @@ type AuthenticationWriter struct {
|
||||||
sizeParser ChunkSizeEncoder
|
sizeParser ChunkSizeEncoder
|
||||||
transferType protocol.TransferType
|
transferType protocol.TransferType
|
||||||
padding PaddingLengthGenerator
|
padding PaddingLengthGenerator
|
||||||
|
mu sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAuthenticationWriter(auth Authenticator, sizeParser ChunkSizeEncoder, writer io.Writer, transferType protocol.TransferType, padding PaddingLengthGenerator) *AuthenticationWriter {
|
func NewAuthenticationWriter(auth Authenticator, sizeParser ChunkSizeEncoder, writer io.Writer, transferType protocol.TransferType, padding PaddingLengthGenerator) *AuthenticationWriter {
|
||||||
|
@ -336,6 +338,8 @@ func (w *AuthenticationWriter) writePacket(mb buf.MultiBuffer) error {
|
||||||
|
|
||||||
// WriteMultiBuffer implements buf.Writer.
|
// WriteMultiBuffer implements buf.Writer.
|
||||||
func (w *AuthenticationWriter) WriteMultiBuffer(mb buf.MultiBuffer) error {
|
func (w *AuthenticationWriter) WriteMultiBuffer(mb buf.MultiBuffer) error {
|
||||||
|
w.mu.Lock()
|
||||||
|
defer w.mu.Unlock()
|
||||||
if mb.IsEmpty() {
|
if mb.IsEmpty() {
|
||||||
eb, err := w.seal([]byte{})
|
eb, err := w.seal([]byte{})
|
||||||
common.Must(err)
|
common.Must(err)
|
||||||
|
|
Loading…
Reference in New Issue