Fix: vmess aead writer concurrent write (#1350)
This commit is contained in:
parent
b59d45c660
commit
a40274e2a2
1 changed files with 8 additions and 1 deletions
|
@ -5,6 +5,7 @@ import (
|
|||
"encoding/binary"
|
||||
"errors"
|
||||
"io"
|
||||
"sync"
|
||||
|
||||
"github.com/Dreamacro/clash/common/pool"
|
||||
)
|
||||
|
@ -15,6 +16,8 @@ type aeadWriter struct {
|
|||
nonce [32]byte
|
||||
count uint16
|
||||
iv []byte
|
||||
|
||||
writeLock sync.Mutex
|
||||
}
|
||||
|
||||
func newAEADWriter(w io.Writer, aead cipher.AEAD, iv []byte) *aeadWriter {
|
||||
|
@ -22,8 +25,12 @@ func newAEADWriter(w io.Writer, aead cipher.AEAD, iv []byte) *aeadWriter {
|
|||
}
|
||||
|
||||
func (w *aeadWriter) Write(b []byte) (n int, err error) {
|
||||
w.writeLock.Lock()
|
||||
buf := pool.Get(pool.RelayBufferSize)
|
||||
defer pool.Put(buf)
|
||||
defer func() {
|
||||
w.writeLock.Unlock()
|
||||
pool.Put(buf)
|
||||
}()
|
||||
length := len(b)
|
||||
for {
|
||||
if length == 0 {
|
||||
|
|
Loading…
Reference in a new issue