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
yuhan6665 2025-09-14 23:33:23 -04:00
parent e188993d4a
commit 4eadb8ff64
1 changed files with 4 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import (
"crypto/cipher"
"crypto/rand"
"io"
"sync"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/buf"
@ -231,6 +232,7 @@ type AuthenticationWriter struct {
sizeParser ChunkSizeEncoder
transferType protocol.TransferType
padding PaddingLengthGenerator
mu sync.Mutex
}
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.
func (w *AuthenticationWriter) WriteMultiBuffer(mb buf.MultiBuffer) error {
w.mu.Lock()
defer w.mu.Unlock()
if mb.IsEmpty() {
eb, err := w.seal([]byte{})
common.Must(err)