Skip to content

Commit

Permalink
Fix user download stats with splice
Browse files Browse the repository at this point in the history
  • Loading branch information
yuhan6665 committed Mar 8, 2024
1 parent 6991c11 commit ab14b42
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"time"

"github.com/pires/go-proxyproto"
"github.com/xtls/xray-core/app/dispatcher"
"github.com/xtls/xray-core/common/buf"
"github.com/xtls/xray-core/common/errors"
"github.com/xtls/xray-core/common/net"
Expand Down Expand Up @@ -478,14 +479,18 @@ func CopyRawConnIfExist(ctx context.Context, readerConn net.Conn, writerConn net
for inbound.CanSpliceCopy != 3 {
if inbound.CanSpliceCopy == 1 {
newError("CopyRawConn splice").WriteToLog(session.ExportIDToError(ctx))
statWriter, _ := writer.(*dispatcher.SizeStatWriter)
//runtime.Gosched() // necessary
time.Sleep(time.Millisecond) // without this, there will be a rare ssl error for freedom splice
w, err := tc.ReadFrom(readerConn)
if readCounter != nil {
readCounter.Add(w)
readCounter.Add(w) // outbound stats
}
if writeCounter != nil {
writeCounter.Add(w)
writeCounter.Add(w) // inbound stats
}
if statWriter != nil {
statWriter.Counter.Add(w) // user stats
}
if err != nil && errors.Cause(err) != io.EOF {
return err
Expand Down

0 comments on commit ab14b42

Please sign in to comment.