fix error handling in vmess outbound

pull/876/head
Darien Raymond 7 years ago
parent e7858e78d5
commit 226d65c6c7
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169

@ -109,6 +109,8 @@ func (v *Handler) Process(ctx context.Context, outboundRay ray.OutboundRay, dial
timer := signal.CancelAfterInactivity(ctx, cancel, sessionPolicy.Timeouts.ConnectionIdle) timer := signal.CancelAfterInactivity(ctx, cancel, sessionPolicy.Timeouts.ConnectionIdle)
requestDone := signal.ExecuteAsync(func() error { requestDone := signal.ExecuteAsync(func() error {
defer timer.SetTimeout(sessionPolicy.Timeouts.DownlinkOnly)
writer := buf.NewBufferedWriter(buf.NewWriter(conn)) writer := buf.NewBufferedWriter(buf.NewWriter(conn))
if err := session.EncodeRequestHeader(request, writer); err != nil { if err := session.EncodeRequestHeader(request, writer); err != nil {
return newError("failed to encode request").Base(err).AtWarning() return newError("failed to encode request").Base(err).AtWarning()
@ -139,23 +141,23 @@ func (v *Handler) Process(ctx context.Context, outboundRay ray.OutboundRay, dial
return err return err
} }
} }
timer.SetTimeout(sessionPolicy.Timeouts.DownlinkOnly)
return nil return nil
}) })
responseDone := signal.ExecuteAsync(func() error { responseDone := signal.ExecuteAsync(func() error {
defer output.Close()
defer timer.SetTimeout(sessionPolicy.Timeouts.UplinkOnly) defer timer.SetTimeout(sessionPolicy.Timeouts.UplinkOnly)
reader := buf.NewBufferedReader(buf.NewReader(conn)) reader := buf.NewBufferedReader(buf.NewReader(conn))
header, err := session.DecodeResponseHeader(reader) header, err := session.DecodeResponseHeader(reader)
if err != nil { if err != nil {
return err return newError("failed to read header").Base(err)
} }
v.handleCommand(rec.Destination(), header.Command) v.handleCommand(rec.Destination(), header.Command)
reader.SetBuffered(false) reader.SetBuffered(false)
bodyReader := session.DecodeResponseBody(request, reader) bodyReader := session.DecodeResponseBody(request, reader)
return buf.Copy(bodyReader, output, buf.UpdateActivity(timer)) return buf.Copy(bodyReader, output, buf.UpdateActivity(timer))
}) })

Loading…
Cancel
Save