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

Properly way to check for closed connection #51

Closed
ltpquang opened this issue Dec 10, 2018 · 2 comments
Closed

Properly way to check for closed connection #51

ltpquang opened this issue Dec 10, 2018 · 2 comments

Comments

@ltpquang
Copy link

ltpquang commented Dec 10, 2018

Hi there, is there any way to check if a Conn is valid before sending the message? I'm currently doing as follow

err := conn.Send(queueName, "text/plain", message)
if err != nil && err.Error() == "connection already closed" {
	// report error
}

The Conn struct has closed property but since it is not exposed and have no access function, I have no way to check the connection before sending.

@worg
Copy link
Collaborator

worg commented Dec 11, 2018

Currently there's no other way, because there might happen that a frame fails [therefore closing the connection according to the spec] during the sending of the message, even if we exposed the closed property it might fail after the closed check and before the actual sending of the frame.

@tahseenjamal
Copy link

You can unmarshal Conn to a struct similar to that of Conn and then read the bool closed value. So no need to be dependent on 'closed' to be exposed

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

3 participants