Skip to content

Commit 4eadb8f

Browse files
committed
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.
1 parent e188993 commit 4eadb8f

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

common/crypto/auth.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"crypto/cipher"
55
"crypto/rand"
66
"io"
7+
"sync"
78

89
"github.com/xtls/xray-core/common"
910
"github.com/xtls/xray-core/common/buf"
@@ -231,6 +232,7 @@ type AuthenticationWriter struct {
231232
sizeParser ChunkSizeEncoder
232233
transferType protocol.TransferType
233234
padding PaddingLengthGenerator
235+
mu sync.Mutex
234236
}
235237

236238
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 {
336338

337339
// WriteMultiBuffer implements buf.Writer.
338340
func (w *AuthenticationWriter) WriteMultiBuffer(mb buf.MultiBuffer) error {
341+
w.mu.Lock()
342+
defer w.mu.Unlock()
339343
if mb.IsEmpty() {
340344
eb, err := w.seal([]byte{})
341345
common.Must(err)

0 commit comments

Comments
 (0)