1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-26 05:46:10 -04:00

cancel context after finish

This commit is contained in:
Darien Raymond 2017-03-31 21:10:33 +02:00
parent 4b15ff5034
commit a57531ef5d
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
9 changed files with 17 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 {

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 {

View File

@ -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 {