Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@floatingstatic
Copy link
Contributor

I seem to have hit the problem described in #90

I run stayrtr in few locations globally and some clients have a high RTT reaching my RTR server instances. It seems like as a result I often am not receiving error reports from stayrtr before the tcp connection is closed, which is unfortunately needed as most of my clients are BIRD 2.x attempting to use RTR version 2 which is not supported by stayrtr at this time. Another side effect of this problem is that due to the way the code is currently implemented I end up with a goroutine leak tied SendRawPDU(). This is fairly easy to simulate using tc-netem on either the client or server side. I have PCAPs and pprof output if any evidence is needed.

This change introduces an errgroup to manage the client read and write loops. Whenever anything calls Disconnect() on the client we cancel the context. The errgroup ensures that both the read and write loops are cleanly stopped before closing the tcp connection. After running a canary of this for a while this seems to have resolved the problem for me.

@benjojo
Copy link
Collaborator

benjojo commented May 24, 2025

Most of this diff is just formatting edits, are you using a weird gofmt? Ideally the diff only has the real change! Otherwise doing git blame and etc becomes a lot harder in the future

@floatingstatic
Copy link
Contributor Author

Hi @benjojo , apologies, I'm not sure why vscode made all of those extra formatting edits. I'm just using stock extensions for go and nothing else. For what its worth just running gofmt outside of the IDE in the master branch shows that it would actually change several files so it seems perhaps the code isn't formatting properly to start with:

$ gofmt -l .
cmd/rtrdump/rtrdump.go
cmd/rtrmon/rtrmon.go
cmd/stayrtr/stayrtr_test.go
lib/server.go
lib/server_test.go
ossec/constrain.go
prefixfile/prefixfile.go
prefixfile/slurm.go
$ go version
go version go1.24.2 darwin/arm64

Later today I can try to push a change without the formatting edits to make my specific change easier to consume.

@benjojo
Copy link
Collaborator

benjojo commented May 24, 2025

Ah, if "stock" go fmt wants to do that, then could you just make a commit go fmt-ing everything, and then put your change on top, otherwise this PR looks good to me (thank you!)

@floatingstatic
Copy link
Contributor Author

@benjojo I force-pushed a change that omits the extra formatting. There was also one minor tweak in moving the client read loop into a dedicated function so the Start() routine looks more tidy.
I figure if we want to handle formatting changes we can do that in another PR/change

@benjojo benjojo merged commit 4808027 into bgp:master May 24, 2025
3 checks passed
@floatingstatic floatingstatic deleted the fix-err-report-race branch May 27, 2025 14:44
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.

2 participants