From bf35e9dcd6391fac01f348d420d062d5640262f1 Mon Sep 17 00:00:00 2001 From: pocketW <104479902+pocketW@users.noreply.github.com> Date: Fri, 20 Jan 2023 22:42:49 +1100 Subject: [PATCH] fix: handle error raised by dispatcher --- transport/internet/udp/dispatcher.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/transport/internet/udp/dispatcher.go b/transport/internet/udp/dispatcher.go index dda26e6e..a8d9c6f5 100644 --- a/transport/internet/udp/dispatcher.go +++ b/transport/internet/udp/dispatcher.go @@ -51,12 +51,12 @@ func (v *Dispatcher) RemoveRay(dest net.Destination) { } } -func (v *Dispatcher) getInboundRay(ctx context.Context, dest net.Destination) *connEntry { +func (v *Dispatcher) getInboundRay(ctx context.Context, dest net.Destination) (*connEntry, error) { v.Lock() defer v.Unlock() if entry, found := v.conns[dest]; found { - return entry + return entry, nil } newError("establishing new connection for ", dest).WriteToLog() @@ -67,7 +67,12 @@ func (v *Dispatcher) getInboundRay(ctx context.Context, dest net.Destination) *c v.RemoveRay(dest) } timer := signal.CancelAfterInactivity(ctx, removeRay, time.Minute) - link, _ := v.dispatcher.Dispatch(ctx, dest) + + link, err := v.dispatcher.Dispatch(ctx, dest) + if err != nil { + return nil, newError("failed to dispatch request to ", dest).Base(err) + } + entry := &connEntry{ link: link, timer: timer, @@ -75,14 +80,18 @@ func (v *Dispatcher) getInboundRay(ctx context.Context, dest net.Destination) *c } v.conns[dest] = entry go handleInput(ctx, entry, dest, v.callback) - return entry + return entry, nil } func (v *Dispatcher) Dispatch(ctx context.Context, destination net.Destination, payload *buf.Buffer) { // TODO: Add user to destString newError("dispatch request to: ", destination).AtDebug().WriteToLog(session.ExportIDToError(ctx)) - conn := v.getInboundRay(ctx, destination) + conn, err := v.getInboundRay(ctx, destination) + if err != nil { + newError("failed to get inbound").Base(err).WriteToLog(session.ExportIDToError(ctx)) + return + } outputStream := conn.link.Writer if outputStream != nil { if err := outputStream.WriteMultiBuffer(buf.MultiBuffer{payload}); err != nil {