Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

creating hsNotifyc as a buffered channel #202

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

AndrewK1273
Copy link

If two clients connect at the same time, an HS notification may be lost because writing to the channel is non-blocking and the channel is not buffered.

@@ -96,7 +96,7 @@ func New(settings *Settings) *StateMachine {
sm := &StateMachine{
cfg: settings,
mux: diam.NewServeMux(),
hsNotifyc: make(chan diam.Conn),
hsNotifyc: make(chan diam.Conn, 10),
Copy link
Owner

Choose a reason for hiding this comment

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

Were you able to reproduce the problem and test with this change? Also I'm curious for what makes "10" the right size for the buffered channel here.

@AndrewK1273
Copy link
Author

AndrewK1273 commented Nov 13, 2024

It depends on how robust it should be.

When I test it with 10 clients connecting simultaneously, which is probably not very likely in the real world, notifications stop being lost when the buffer set to 3 (see attachment).

It also depends on the way notifications are processed on the server side. During the test, I print out originHost.

func (f *FakePcrf) HandshakeNotifyHandler(hn <-chan diam.Conn) {
	for c := range hn {
		if meta, ok := smpeer.FromContext(c.Context()); ok {
			log.Printf("new peer OriginHost: %s", string(meta.OriginHost.Serialize()))
		}
	}
}

The value of 10 seemed like a sufficient reserve even for a very crazy case.
diam_hs_notif_tests.txt

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