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

Infinite Error Logging When native.Connect Fails to Dial Asterisk #176

Open
ehsanrocket opened this issue Jan 12, 2025 · 1 comment
Open

Comments

@ehsanrocket
Copy link

When native.Connect fails to establish a WebSocket connection with Asterisk it logs the error repeatedly in an infinite loop.
There should be a way for the native.Connect function to return an error immediately upon encountering a WebSocket connection issue

cl, err := native.Connect(&native.Options{
		Application:  app,
		Logger:       log.With("app", app),
		Username:     ARI_USERNAME,
		Password:     ARI_PASSWORD,
		URL:          "http://" + VOIP_ADDRESS + "/ari",
		WebsocketURL: "ws://" + VOIP_ADDRESS + "/ari/events",
	})
	if err != nil {
		log.Error("Failed to build native ARI client", "error", err)
		cl.Close()
		return false
	}
cl.Close()
return true
	

Steps to Reproduce
1- Configure an incorrect WebSocket URL or invalid credentials.
2- Run the code snippet above.
3- Observe that the error details are not logged adequately.

Expected Behavior
run log.Error("Failed to build native ARI client", "error", err) and return false

Actual Behavior
level=ERROR msg="failed to connect to Asterisk" app=check-qvs44v5 error="websocket.Dial ws://1.2.3.4:8088/ari/events?app=check-qvs44v5: dial tcp 1.2.3.4:8088: connect: connection timed out"
level=ERROR msg="failed to connect to Asterisk" app=check-qvs44v5 error="websocket.Dial ws://1.2.3.4:8088/ari/events?app=check-qvs44v5: dial tcp 1.2.3.4:8088: connect: connection timed out"
level=ERROR msg="failed to connect to Asterisk" app=check-qvs44v5 error="websocket.Dial ws://1.2.3.4:8088/ari/events?app=check-qvs44v5: dial tcp 1.2.3.4:8088: connect: connection timed out"
...

@Ulexus
Copy link
Member

Ulexus commented Jan 14, 2025

The reconnection pattern is important to ensure dropped connections are re-established, but it does seem reasonable to allow an option to fail fast.

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

No branches or pull requests

2 participants