1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2026-05-14 00:19:07 -04:00

close outbound connections when context is done

This commit is contained in:
Darien Raymond
2017-01-28 21:24:46 +01:00
parent 9139a87865
commit fab20bb0cf
12 changed files with 45 additions and 28 deletions

View File

@@ -83,7 +83,7 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn in
return nil
})
if err := signal.ErrorOrFinish2(requestDone, responseDone); err != nil {
if err := signal.ErrorOrFinish2(ctx, requestDone, responseDone); err != nil {
inboundRay.InboundInput().CloseError()
inboundRay.InboundOutput().CloseError()
log.Info("Dokodemo: Connection ends with ", err)

View File

@@ -136,7 +136,7 @@ func (v *Handler) Process(ctx context.Context, outboundRay ray.OutboundRay) erro
return nil
})
if err := signal.ErrorOrFinish2(requestDone, responseDone); err != nil {
if err := signal.ErrorOrFinish2(ctx, requestDone, responseDone); err != nil {
log.Info("Freedom: Connection ending with ", err)
input.CloseError()
output.CloseError()

View File

@@ -150,7 +150,7 @@ func (s *Server) handleConnect(ctx context.Context, request *http.Request, reade
return nil
})
if err := signal.ErrorOrFinish2(requestDone, responseDone); err != nil {
if err := signal.ErrorOrFinish2(ctx, requestDone, responseDone); err != nil {
log.Info("HTTP|Server: Connection ends with: ", err)
ray.InboundInput().CloseError()
ray.InboundOutput().CloseError()
@@ -246,7 +246,7 @@ func (s *Server) handlePlainHTTP(ctx context.Context, request *http.Request, rea
return nil
})
if err := signal.ErrorOrFinish2(requestDone, responseDone); err != nil {
if err := signal.ErrorOrFinish2(ctx, requestDone, responseDone); err != nil {
log.Info("HTTP|Server: Connecton ending with ", err)
input.CloseError()
output.CloseError()

View File

@@ -61,6 +61,7 @@ func (v *Client) Process(ctx context.Context, outboundRay ray.OutboundRay) error
}
log.Info("Shadowsocks|Client: Tunneling request to ", destination, " via ", server.Destination())
defer conn.Close()
conn.SetReusable(false)
request := &protocol.RequestHeader{
@@ -119,7 +120,7 @@ func (v *Client) Process(ctx context.Context, outboundRay ray.OutboundRay) error
return nil
})
if err := signal.ErrorOrFinish2(requestDone, responseDone); err != nil {
if err := signal.ErrorOrFinish2(ctx, requestDone, responseDone); err != nil {
log.Info("Shadowsocks|Client: Connection ends with ", err)
outboundRay.OutboundInput().CloseError()
outboundRay.OutboundOutput().CloseError()
@@ -161,10 +162,8 @@ func (v *Client) Process(ctx context.Context, outboundRay ray.OutboundRay) error
return nil
})
if err := signal.ErrorOrFinish2(requestDone, responseDone); err != nil {
if err := signal.ErrorOrFinish2(ctx, requestDone, responseDone); err != nil {
log.Info("Shadowsocks|Client: Connection ends with ", err)
outboundRay.OutboundInput().CloseError()
outboundRay.OutboundOutput().CloseError()
return err
}

View File

@@ -69,6 +69,8 @@ func (s *Server) Network() net.NetworkList {
}
func (s *Server) Process(ctx context.Context, network net.Network, conn internet.Connection) error {
conn.SetReusable(false)
switch network {
case net.Network_TCP:
return s.handleConnection(ctx, conn)
@@ -132,8 +134,6 @@ func (v *Server) handlerUDPPayload(ctx context.Context, conn internet.Connection
}
func (s *Server) handleConnection(ctx context.Context, conn internet.Connection) error {
conn.SetReusable(false)
timedReader := net.NewTimeOutReader(16, conn)
bufferedReader := bufio.NewReader(timedReader)
request, bodyReader, err := ReadTCPSession(s.user, bufferedReader)
@@ -195,7 +195,7 @@ func (s *Server) handleConnection(ctx context.Context, conn internet.Connection)
return nil
})
if err := signal.ErrorOrFinish2(requestDone, responseDone); err != nil {
if err := signal.ErrorOrFinish2(ctx, requestDone, responseDone); err != nil {
log.Info("Shadowsocks|Server: Connection ends with ", err)
ray.InboundInput().CloseError()
ray.InboundOutput().CloseError()

View File

@@ -108,10 +108,8 @@ func (c *Client) Process(ctx context.Context, ray ray.OutboundRay) error {
requestDone := signal.ExecuteAsync(requestFunc)
responseDone := signal.ExecuteAsync(responseFunc)
if err := signal.ErrorOrFinish2(requestDone, responseDone); err != nil {
if err := signal.ErrorOrFinish2(ctx, requestDone, responseDone); err != nil {
log.Info("Socks|Client: Connection ends with ", err)
ray.OutboundInput().CloseError()
ray.OutboundOutput().CloseError()
return err
}

View File

@@ -137,10 +137,9 @@ func (v *Server) transport(ctx context.Context, reader io.Reader, writer io.Writ
return err
}
return nil
})
if err := signal.ErrorOrFinish2(requestDone, responseDone); err != nil {
if err := signal.ErrorOrFinish2(ctx, requestDone, responseDone); err != nil {
log.Info("Socks|Server: Connection ends with ", err)
input.CloseError()
output.CloseError()

View File

@@ -222,7 +222,7 @@ func (v *VMessInboundHandler) Process(ctx context.Context, network net.Network,
return transferResponse(session, request, response, output, writer)
})
if err := signal.ErrorOrFinish2(requestDone, responseDone); err != nil {
if err := signal.ErrorOrFinish2(ctx, requestDone, responseDone); err != nil {
log.Info("VMess|Inbound: Connection ending with ", err)
connection.SetReusable(false)
input.CloseError()

View File

@@ -152,11 +152,9 @@ func (v *VMessOutboundHandler) Process(ctx context.Context, outboundRay ray.Outb
return nil
})
if err := signal.ErrorOrFinish2(requestDone, responseDone); err != nil {
if err := signal.ErrorOrFinish2(ctx, requestDone, responseDone); err != nil {
log.Info("VMess|Outbound: Connection ending with ", err)
conn.SetReusable(false)
input.CloseError()
output.CloseError()
return err
}