mirror of https://github.com/v2ray/v2ray-core
				
				
				
			cancel context after finish
							parent
							
								
									4b15ff5034
								
							
						
					
					
						commit
						a57531ef5d
					
				| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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 {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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 {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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 {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue