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

ResponseTimeout is not configurable on per message basis #43

Open
kulak opened this issue Apr 18, 2017 · 5 comments
Open

ResponseTimeout is not configurable on per message basis #43

kulak opened this issue Apr 18, 2017 · 5 comments

Comments

@kulak
Copy link

kulak commented Apr 18, 2017

ResponseTimeout const control message response timeout and it is set to 2 seconds.

While 2 seconds timeout is ok for 1st message, when message is re transmitted the timeout value needs to be increased. Thus, we need to be able to supply custom ResponseTimeout with the request data as it appears to be a higher level function in this API design.

const (
	// ResponseTimeout is the amount of time to wait for a
	// response.
	ResponseTimeout = time.Second * 2
)

// Receive a message.
func Receive(l *net.UDPConn, buf []byte) (Message, error) {
	l.SetReadDeadline(time.Now().Add(ResponseTimeout))

	nr, _, err := l.ReadFromUDP(buf)
	if err != nil {
		return Message{}, err
	}
	return parseMessage(buf[:nr])
}
@drasko
Copy link

drasko commented Apr 30, 2017

Also, I can notice that in the example/obsclient we are trying simple Receive() which timeouts observation after 2 sec: https://github.com/dustin/go-coap/blob/master/example/obsclient/obsclient.go#L37

This timeout must be modifiable, as we might decide to wait on receive for a long time in a separate goroutine (we observe some value and we do not know in which moment the value will come - after 2 seconds or after 10 minutes...)

kulak pushed a commit to kulak/go-coap that referenced this issue Jun 6, 2017
1. changed examples to use this package
2. response timeout issue is recorded in original repo at dustin#43
@kulak
Copy link
Author

kulak commented Jun 6, 2017

Hi,

I generally don't contribute to github, so I am not sure how it all works.

I have my own fork where I have addressed the issue, because our solution requires a control over response timeout at client level.

Here is a single commit where I address the issue. I have added a test case to verify that I have addressed timeout:

kulak@4ac9ea7

The solution I chose is backwards compatible, but it introduces new variant of Dial function. I added a variable to track timeout parameter. I have renamed original ResponseTimeout to be DefaultResponseTimeout, because I wanted to make sure I've got all use cases and because its meaning is to be the default.

I am personally not sure if it would've been better to request for timeout as an argument to Send call. Compatibility and simplicity of API won over and I added response timeout to Connection structure instead.

If there is an interest in merge, I will request a pull for merge.

@dustin
Copy link
Owner

dustin commented Jun 7, 2017 via email

@kulak
Copy link
Author

kulak commented Jun 7, 2017

Context is a very good approach. I did not even think about it as I don't usually use it because of similar reason of code base older than context. I've used context concept in .NET apps and it is a great solution to many issues with logical operation context.

@bgentry
Copy link

bgentry commented Aug 2, 2017

@dustin I definitely agree that utilizing context.Context is the way to go here. You can model it after what net/http does and make the context a part of the coap.Message. Handlers would be expected to respect ctx.Done() as they are in HTTP these days.

neilalexander pushed a commit to neilalexander/go-coap that referenced this issue Jun 12, 2020
* fix multicast write for windows

- multicast client now listen on free port to avoid share it among other
clients
- join group to all OS interfaces when provided interfaces are nil
- fix noresponse test
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

4 participants