-
Notifications
You must be signed in to change notification settings - Fork 96
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
add connection timeout function #140
Conversation
Hello, can you take a look at this pr @worg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add a couple of tests for this? specially covering the deadline from context
conn.go
Outdated
response, err := reader.Read() | ||
if err != nil { | ||
return nil, err | ||
} | ||
if ok && isNetConn { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't this the same as the check on line 165? I think you meant to use !ok
also why SetReadDeadline
and not SetDeadline
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
additionaly, can we move this one above so it's next to the other if
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem to be solved here is that after the stomp client sends the stomp protocol connect message, the stomp server does not reply due to some reasons, such as: stomp server resources are insufficient stomp client message, and the stomp client will block forever. The use of SetReadDeadline here is correct because we want reader.Read() to time out instead of blocking forever, Calling SetReadDeadline again at line 173 with the argument time.Time{} restores net.Conn's read blocking behavior because we don't want it to affect subsequent data interactions. thank you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok |
Hello, the current implementation of Dial does not have a timeout , in some cases we should need to specify a connection timeout. So I added a DialWithContext function.
I tried to write it like this before:
but this is not guaranteed to be correct, however, because the code in the Connect function: go readLoop(c, reader) -->
may be executed before recover SetReadDeadline, And just in time for the deadline causing read coroutines to exit.
thank you