mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-12-01 06:08:37 +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.
|
// NewClientWorker creates a new mux.Client.
|
||||||
func NewClientWorker(stream transport.Link, s ClientStrategy) (*ClientWorker, error) {
|
func NewClientWorker(stream transport.Link, s ClientStrategy) (*ClientWorker, error) {
|
||||||
|
stream.Writer = &MutexWriter{Writer: stream.Writer}
|
||||||
c := &ClientWorker{
|
c := &ClientWorker{
|
||||||
sessionManager: NewSessionManager(),
|
sessionManager: NewSessionManager(),
|
||||||
link: stream,
|
link: stream,
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ type ServerWorker struct {
|
|||||||
func NewServerWorker(ctx context.Context, d routing.Dispatcher, link *transport.Link) (*ServerWorker, error) {
|
func NewServerWorker(ctx context.Context, d routing.Dispatcher, link *transport.Link) (*ServerWorker, error) {
|
||||||
worker := &ServerWorker{
|
worker := &ServerWorker{
|
||||||
dispatcher: d,
|
dispatcher: d,
|
||||||
link: link,
|
link: &transport.Link{Reader: link.Reader, Writer: &MutexWriter{Writer: link.Writer}},
|
||||||
sessionManager: NewSessionManager(),
|
sessionManager: NewSessionManager(),
|
||||||
done: done.New(),
|
done: done.New(),
|
||||||
timer: time.NewTicker(60 * time.Second),
|
timer: time.NewTicker(60 * time.Second),
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package mux
|
package mux
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"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"
|
||||||
"github.com/xtls/xray-core/common/net"
|
"github.com/xtls/xray-core/common/net"
|
||||||
@@ -9,6 +11,17 @@ import (
|
|||||||
"github.com/xtls/xray-core/common/session"
|
"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 {
|
type Writer struct {
|
||||||
dest net.Destination
|
dest net.Destination
|
||||||
writer buf.Writer
|
writer buf.Writer
|
||||||
|
|||||||
Reference in New Issue
Block a user