Skip to content

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

@ehsanrocket

Description

@ehsanrocket

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions