Skip to content

Commit

Permalink
fix: break out of reading from the association if we can't get to rel…
Browse files Browse the repository at this point in the history
…ay (#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.
  • Loading branch information
sbruens authored Feb 27, 2025
1 parent 76c20d6 commit 9621558
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions service/udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ func (h *associationHandler) HandleAssociation(ctx context.Context, clientConn n
var proxyTargetBytes int

connError := func() *onet.ConnectionError {
// Error from `clientConn.Read()`.
if err != nil {
return onet.NewConnectionError("ERR_READ", "Failed to read from association", err)
}

var payload []byte
var tgtUDPAddr *net.UDPAddr
if targetConn == nil {
Expand Down Expand Up @@ -233,6 +238,11 @@ func (h *associationHandler) HandleAssociation(ctx context.Context, clientConn n
status = connError.Status
}
assocMetrics.AddPacketFromClient(status, int64(clientProxyBytes), int64(proxyTargetBytes))
if targetConn == nil {
// If there's still no target connection, we didn't authenticate. Break out of handling the
// association here so resources can be released.
break
}
}
}

Expand Down

0 comments on commit 9621558

Please sign in to comment.