Skip to content

Commit 4e826ab

Browse files
authored
Chore: Three small fixes (#4922)
1 parent 4433641 commit 4e826ab

File tree

5 files changed

+16
-3
lines changed

5 files changed

+16
-3
lines changed

app/proxyman/inbound/worker.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ type udpConn struct {
161161
uplink stats.Counter
162162
downlink stats.Counter
163163
inactive bool
164+
cancel context.CancelFunc
164165
}
165166

166167
func (c *udpConn) setInactive() {
@@ -203,6 +204,9 @@ func (c *udpConn) Write(buf []byte) (int, error) {
203204
}
204205

205206
func (c *udpConn) Close() error {
207+
if c.cancel != nil {
208+
c.cancel()
209+
}
206210
common.Must(c.done.Close())
207211
common.Must(common.Close(c.writer))
208212
return nil
@@ -259,6 +263,7 @@ func (w *udpWorker) getConnection(id connID) (*udpConn, bool) {
259263
defer w.Unlock()
260264

261265
if conn, found := w.activeConn[id]; found && !conn.done.Done() {
266+
conn.updateActivity()
262267
return conn, true
263268
}
264269

@@ -306,7 +311,8 @@ func (w *udpWorker) callback(b *buf.Buffer, source net.Destination, originalDest
306311
common.Must(w.checker.Start())
307312

308313
go func() {
309-
ctx := w.ctx
314+
ctx, cancel := context.WithCancel(w.ctx)
315+
conn.cancel = cancel
310316
sid := session.NewID()
311317
ctx = c.ContextWithID(ctx, sid)
312318

proxy/shadowsocks/server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ func (s *Server) handleUDPPayload(ctx context.Context, conn stat.Connection, dis
128128

129129
conn.Write(data.Bytes())
130130
})
131+
defer udpServer.RemoveRay()
131132

132133
inbound := session.InboundFromContext(ctx)
133134
var dest *net.Destination

proxy/socks/server.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,13 +245,15 @@ func (s *Server) handleUDPPayload(ctx context.Context, conn stat.Connection, dis
245245
udpMessage, err := EncodeUDPPacket(request, payload.Bytes())
246246
payload.Release()
247247

248-
defer udpMessage.Release()
249248
if err != nil {
250249
errors.LogWarningInner(ctx, err, "failed to write UDP response")
250+
return
251251
}
252+
defer udpMessage.Release()
252253

253254
conn.Write(udpMessage.Bytes())
254255
})
256+
defer udpServer.RemoveRay()
255257

256258
inbound := session.InboundFromContext(ctx)
257259
if inbound != nil && inbound.Source.IsValid() {

proxy/trojan/server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ func (s *Server) handleUDPPayload(ctx context.Context, clientReader *PacketReade
259259
errors.LogWarningInner(ctx, err, "failed to write response")
260260
}
261261
})
262+
defer udpServer.RemoveRay()
262263

263264
inbound := session.InboundFromContext(ctx)
264265
user := inbound.User

proxy/vless/inbound/inbound.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,10 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection s
206206

207207
first := buf.FromBytes(make([]byte, buf.Size))
208208
first.Clear()
209-
firstLen, _ := first.ReadFrom(connection)
209+
firstLen, errR := first.ReadFrom(connection)
210+
if errR != nil {
211+
return errR
212+
}
210213
errors.LogInfo(ctx, "firstLen = ", firstLen)
211214

212215
reader := &buf.BufferedReader{

0 commit comments

Comments
 (0)