ari icon indicating copy to clipboard operation
ari copied to clipboard

Infinite Error Logging When native.Connect Fails to Dial Asterisk

Open ehsanrocket opened this issue 1 year ago • 1 comments

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" ...

ehsanrocket avatar Jan 12 '25 13:01 ehsanrocket

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

Ulexus avatar Jan 14 '25 14:01 Ulexus