-
Notifications
You must be signed in to change notification settings - Fork 409
Request Timeout
Timeout is a bit complex in CoAP/LWM2M. Let's see in details.
This timeout is the maximum time to wait for a response. Let's call this the response timeout. You could choose the timeout for each requests like this :
leshanServer.send(destination, requestToSend, timeoutInMs);
The default value is 2 minutes which is a bit longer than the CoAP timeout. response timeout is not the only way a request could timed out. Let's see the other-ones.
In CoAP a request could be Confirmable, this means that's the peer receiving the request should acknowledged it. There is a mechanism of retransmission. If request is not acknowledged after all retransmissions. The request will timed-out too. See RFC-7252-§4.2 for more details. Let's call this the CoAP timeout. This value can be set for all requests via the coapConfig.
LeshanServerBuilder builder = new LeshanServerBuilder();
NetworkConfig coapConfig = LeshanServerBuilder.createDefaultNetworkConfig();
// here is the default value
coapConfig.setInt(NetworkConfig.Keys.ACK_TIMEOUT, 2000); // in ms
coapConfig.setFloat(NetworkConfig.Keys.ACK_RANDOM_FACTOR, 1.5f);
coapConfig.setFloat(NetworkConfig.Keys.ACK_TIMEOUT_SCALE, 2f);
coapConfig.setInt(NetworkConfig.Keys.MAX_RETRANSMIT, 4);
// with this value, a none-acknowledged confirmable request should timeout between 62s and 93s.
// see MAX_TRANSMIT_WAIT in the RFC-7252
builder.setCoapConfig(coapConfig);
This acknowledgement just mean "I receive your request and I will respond soon", so a request can be acknowledged but we never receive a response. In this case the request will timed-out because of response timeout.
Note that in CoAP you can send acknowledgement and response in the same packet (called piggyback)
Leshan use californium transparent blockwise. This mean that blockwise mode is automatically use when payload is too large. (see RFC-7959) If any of the block request is not acknowledged in time the request will timed-out (see CoAP timeout)
The maximum time between "a block request and a block response" or between "a block response and a block request" is BLOCKWISE_STATUS_LIFETIME
(5min by default).
If no request or response is received in this expected time, the request will timed-out too.
Let's call this Block timeout
This value can be set for all block requests via the coapConfig.
LeshanServerBuilder builder = new LeshanServerBuilder();
NetworkConfig coapConfig = LeshanServerBuilder.createDefaultNetworkConfig();
coapConfig.setInt(NetworkConfig.Keys.BLOCKWISE_STATUS_LIFETIME, 5*60*1000); // in ms
builder.setCoapConfig(coapConfig);
If when sending the request there is no DTLS connection available, a new DTLS handshake could be initiated. If we don't get handshake flight answer in time, handshake can time-out. (see RFC6347§4.2.4)
The value can be change using :
LeshanServerBuilder builder = super.createServerBuilder();
Builder dtlsConfig = new DtlsConnectorConfig.Builder();
dtlsConfig.setMaxRetransmissions(4);
dtlsConfig.setRetransmissionTimeout(1000); // in ms
builder.setDtlsConfig(dtlsConfig);
The default value (4 retransmission with 1s of retransmission timeout) makes that a flight will time-out in around 31s.
When a request timed out in any way all the internal data relative to this request will be released. It's up to you to define the right value for all this timeout. If you plan to send or receive large data using block mode the default 2minutes one is probably too short.
For very large payload, using CoAP block-wise transfer is maybe not the better choice. This study seems to show that TCP-based protocol is more adapted to optimization transmission time over Cellular Networks.
All contributions you make to our web site (including this wiki) are governed by our Terms of Use, so please take the time to actually read it. Your interactions with the Eclipse Foundation web properties and any information you may provide us about yourself are governed by our Privacy Policy.