fix: break out of reading from the association if we can't get to relay#245
Merged
Conversation
749b7cf to
6858264
Compare
sbruens
commented
Feb 25, 2025
| connError := func() *onet.ConnectionError { | ||
| // Error from `clientConn.Read()`. | ||
| if err != nil { | ||
| return onet.NewConnectionError("ERR_READ", "Failed to read from association", err) |
Author
There was a problem hiding this comment.
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.
fortuna
reviewed
Feb 26, 2025
| status = connError.Status | ||
| } | ||
| assocMetrics.AddPacketFromClient(status, int64(clientProxyBytes), int64(proxyTargetBytes)) | ||
| if connError != nil && onet.IsConnectionError(connError, "ERR_READ") { |
There was a problem hiding this comment.
I'm not a fan of this type-unsafe check, but I think it's ok for the quick fix.
Author
There was a problem hiding this comment.
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.
527ec6e to
d28ba6c
Compare
fortuna
approved these changes
Feb 27, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
PacketServePacketConn.ReadFrom()loop, but we shouldn't ignore them at the association'sRead()level.