Skip to content

Commit 9621558

Browse files
authored
fix: break out of reading from the association if we can't get to relay (#245)
* fix: return early on failure to upgrade * fix: add `ERR_READ` connection errors to track non-closure errors * Close the association on invalid ciphers and packets to release resources. * Break out of the association `Read()` loop on non-close read errors. * Add `nil` checks. * Simplify breaking out of the read loop for all initial packet errors. * Simplify further by just checking the `targetConn`. * Remove unnecessary `clientConn.Close()`. * Improve comment slightly.
1 parent 76c20d6 commit 9621558

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

service/udp.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ func (h *associationHandler) HandleAssociation(ctx context.Context, clientConn n
170170
var proxyTargetBytes int
171171

172172
connError := func() *onet.ConnectionError {
173+
// Error from `clientConn.Read()`.
174+
if err != nil {
175+
return onet.NewConnectionError("ERR_READ", "Failed to read from association", err)
176+
}
177+
173178
var payload []byte
174179
var tgtUDPAddr *net.UDPAddr
175180
if targetConn == nil {
@@ -233,6 +238,11 @@ func (h *associationHandler) HandleAssociation(ctx context.Context, clientConn n
233238
status = connError.Status
234239
}
235240
assocMetrics.AddPacketFromClient(status, int64(clientProxyBytes), int64(proxyTargetBytes))
241+
if targetConn == nil {
242+
// If there's still no target connection, we didn't authenticate. Break out of handling the
243+
// association here so resources can be released.
244+
break
245+
}
236246
}
237247
}
238248

0 commit comments

Comments
 (0)