Skip to content

fix: break out of reading from the association if we can't get to relay#245

Merged
sbruens merged 10 commits into
masterfrom
sbruens/udp-fix
Feb 27, 2025
Merged

fix: break out of reading from the association if we can't get to relay#245
sbruens merged 10 commits into
masterfrom
sbruens/udp-fix

Conversation

@sbruens

@sbruens sbruens commented Feb 25, 2025

Copy link
Copy Markdown

Before 6a15c34, associations were added to the NAT map only after successful authentication and packet validation. Now that NAT handling is separate, associations are added before packet handling. But the relay routine isn't called, so no one is cleaning them up.

To ensure proper cleanup, we now exit from the read loop on invalid initial packets. This ensures the association handler returns. Without this change, associations and goroutines would remain open and never be removed from the NAT map.

We also add non-close read errors at the association level handling. We ignore read errors at the connection level inside the PacketServe PacketConn.ReadFrom() loop, but we shouldn't ignore them at the association's Read() level.

@sbruens sbruens changed the title Sbruens/udp fix fix: close the association if we can't get to a relay Feb 25, 2025
Base automatically changed from sbruens/non-ws to master February 25, 2025 13:56
Comment thread service/udp.go
connError := func() *onet.ConnectionError {
// Error from `clientConn.Read()`.
if err != nil {
return onet.NewConnectionError("ERR_READ", "Failed to read from association", err)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This status error was lost in the refactor. Rather than break above on read errors, this is more in line with how we used to do it, so that we can add these errors to metrics.

@sbruens sbruens marked this pull request as ready for review February 25, 2025 16:23
@sbruens sbruens requested a review from a team as a code owner February 25, 2025 16:23
Comment thread service/udp.go Outdated
status = connError.Status
}
assocMetrics.AddPacketFromClient(status, int64(clientProxyBytes), int64(proxyTargetBytes))
if connError != nil && onet.IsConnectionError(connError, "ERR_READ") {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of this type-unsafe check, but I think it's ok for the quick fix.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you help me understand why you think this is type-unsafe? IsConnectionError() does a type check.

Anyway, I've changed the approach slightly so this isn't needed anymore.

Comment thread service/udp.go
@sbruens sbruens requested a review from fortuna February 26, 2025 15:24
@sbruens sbruens changed the title fix: close the association if we can't get to a relay fix: break out of reading from the association if we can't get to a relay Feb 26, 2025
@sbruens sbruens changed the title fix: break out of reading from the association if we can't get to a relay fix: break out of reading from the association if we can't get to relay Feb 26, 2025
@sbruens sbruens merged commit 9621558 into master Feb 27, 2025
@sbruens sbruens deleted the sbruens/udp-fix branch February 27, 2025 04:13
@sbruens sbruens linked an issue Feb 28, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Increased NAT entries and go routines due to packet handling errors

2 participants