Darien Raymond 8 лет назад
Родитель
Сommit
a57531ef5d

+ 2 - 0
proxy/dokodemo/dokodemo.go

@@ -61,6 +61,8 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn in
 		return errors.New("Dokodemo: Unable to get destination.")
 	}
 	ctx, cancel := context.WithCancel(ctx)
+	defer cancel()
+
 	timeout := time.Second * time.Duration(d.config.Timeout)
 	if timeout == 0 {
 		timeout = time.Minute * 2

+ 2 - 1
proxy/freedom/freedom.go

@@ -109,6 +109,8 @@ func (v *Handler) Process(ctx context.Context, outboundRay ray.OutboundRay, dial
 	conn.SetReusable(false)
 
 	ctx, cancel := context.WithCancel(ctx)
+	defer cancel()
+
 	timeout := time.Second * time.Duration(v.timeout)
 	if timeout == 0 {
 		timeout = time.Minute * 5
@@ -136,7 +138,6 @@ func (v *Handler) Process(ctx context.Context, outboundRay ray.OutboundRay, dial
 
 	if err := signal.ErrorOrFinish2(ctx, requestDone, responseDone); err != nil {
 		log.Info("Freedom: Connection ending with ", err)
-		cancel()
 		input.CloseError()
 		output.CloseError()
 		return err

+ 2 - 0
proxy/http/server.go

@@ -122,6 +122,8 @@ func (s *Server) handleConnect(ctx context.Context, request *http.Request, reade
 	}
 
 	ctx, cancel := context.WithCancel(ctx)
+	defer cancel()
+
 	timeout := time.Second * time.Duration(s.config.Timeout)
 	if timeout == 0 {
 		timeout = time.Minute * 2

+ 2 - 0
proxy/shadowsocks/client.go

@@ -91,6 +91,8 @@ func (v *Client) Process(ctx context.Context, outboundRay ray.OutboundRay, diale
 	}
 
 	ctx, cancel := context.WithCancel(ctx)
+	defer cancel()
+
 	timer := signal.CancelAfterInactivity(ctx, cancel, time.Minute*2)
 
 	if request.Command == protocol.RequestCommandTCP {

+ 1 - 0
proxy/shadowsocks/server.go

@@ -196,6 +196,7 @@ func (s *Server) handleConnection(ctx context.Context, conn internet.Connection,
 
 	if err := signal.ErrorOrFinish2(ctx, requestDone, responseDone); err != nil {
 		log.Info("Shadowsocks|Server: Connection ends with ", err)
+		cancel()
 		ray.InboundInput().CloseError()
 		ray.InboundOutput().CloseError()
 		return err

+ 2 - 0
proxy/socks/client.go

@@ -82,6 +82,8 @@ func (c *Client) Process(ctx context.Context, ray ray.OutboundRay, dialer proxy.
 	}
 
 	ctx, cancel := context.WithCancel(ctx)
+	defer cancel()
+
 	timer := signal.CancelAfterInactivity(ctx, cancel, time.Minute*2)
 
 	var requestFunc func() error

+ 2 - 0
proxy/socks/server.go

@@ -111,6 +111,8 @@ func (*Server) handleUDP() error {
 
 func (v *Server) transport(ctx context.Context, reader io.Reader, writer io.Writer, dest net.Destination, dispatcher dispatcher.Interface) error {
 	ctx, cancel := context.WithCancel(ctx)
+	defer cancel()
+
 	timeout := time.Second * time.Duration(v.config.Timeout)
 	if timeout == 0 {
 		timeout = time.Minute * 2

+ 2 - 0
proxy/vmess/inbound/inbound.go

@@ -194,6 +194,8 @@ func (v *Handler) Process(ctx context.Context, network net.Network, connection i
 
 	ctx = protocol.ContextWithUser(ctx, request.User)
 	ctx, cancel := context.WithCancel(ctx)
+	defer cancel()
+
 	timer := signal.CancelAfterInactivity(ctx, cancel, userSettings.PayloadTimeout)
 	ray, err := dispatcher.Dispatch(ctx, request.Destination())
 	if err != nil {

+ 2 - 0
proxy/vmess/outbound/outbound.go

@@ -106,6 +106,8 @@ func (v *Handler) Process(ctx context.Context, outboundRay ray.OutboundRay, dial
 	session := encoding.NewClientSession(protocol.DefaultIDHash)
 
 	ctx, cancel := context.WithCancel(ctx)
+	defer cancel()
+
 	timer := signal.CancelAfterInactivity(ctx, cancel, time.Minute*2)
 
 	requestDone := signal.ExecuteAsync(func() error {