mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-11-10 20:22:38 +00:00
VLESS Multiplex (mux.cool): Apply MutexWriter to avoid concurrent writes to the underlayer
https://github.com/XTLS/Xray-core/pull/7337#issuecomment-6692618802 https://github.com/XTLS/Xray-core/pull/7345#issuecomment-6714114884 Fixes https://github.com/XTLS/Xray-core/issues/5845 and https://github.com/XTLS/Xray-core/issues/7336 --------- Co-authored-by: StarProxima <34741787+StarProxima@users.noreply.github.com>
This commit is contained in:
@@ -188,6 +188,7 @@ var (
|
||||
|
||||
// NewClientWorker creates a new mux.Client.
|
||||
func NewClientWorker(stream transport.Link, s ClientStrategy) (*ClientWorker, error) {
|
||||
stream.Writer = &MutexWriter{Writer: stream.Writer}
|
||||
c := &ClientWorker{
|
||||
sessionManager: NewSessionManager(),
|
||||
link: stream,
|
||||
|
||||
@@ -95,7 +95,7 @@ type ServerWorker struct {
|
||||
func NewServerWorker(ctx context.Context, d routing.Dispatcher, link *transport.Link) (*ServerWorker, error) {
|
||||
worker := &ServerWorker{
|
||||
dispatcher: d,
|
||||
link: link,
|
||||
link: &transport.Link{Reader: link.Reader, Writer: &MutexWriter{Writer: link.Writer}},
|
||||
sessionManager: NewSessionManager(),
|
||||
done: done.New(),
|
||||
timer: time.NewTicker(60 * time.Second),
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package mux
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/common/buf"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
@@ -9,6 +11,17 @@ import (
|
||||
"github.com/xtls/xray-core/common/session"
|
||||
)
|
||||
|
||||
type MutexWriter struct {
|
||||
sync.Mutex
|
||||
buf.Writer
|
||||
}
|
||||
|
||||
func (w *MutexWriter) WriteMultiBuffer(mb buf.MultiBuffer) error {
|
||||
w.Lock()
|
||||
defer w.Unlock()
|
||||
return w.Writer.WriteMultiBuffer(mb)
|
||||
}
|
||||
|
||||
type Writer struct {
|
||||
dest net.Destination
|
||||
writer buf.Writer
|
||||
|
||||
Reference in New Issue
Block a user