From 758e307a204b5b66dbf81ab6ed73463d7024f44d Mon Sep 17 00:00:00 2001 From: Mandeep Shetty Date: Fri, 25 Sep 2015 13:52:54 -0700 Subject: [PATCH] Fix duplicate observer registrations due to slow server or network. This fixes IOT-720 and IOT-612. The client retransmits a confirmable request before the 1st timeout for un-acknowledged confirmable request. The server is occasionally too slow to respond or the network is slow sometimes. In case of OBSERVE registrations, a retransmit means two or more observers will be added for one observe request the client sent. This leads to lot's of extra notifications being sent out and only one of observers from the multiple clones are deleted if the client de-registers. Fix is to check with the token if observer was already added and ignore the request if it was as the client was likely already ACKED for the first request the server fully processed. This should be cherrypicked to 1.0.0-dev. Change-Id: I7ecfe1a6e8009606a9430515cbcedef2516507d7 Signed-off-by: Mandeep Shetty Reviewed-on: https://gerrit.iotivity.org/gerrit/3155 Tested-by: jenkins-iotivity Reviewed-by: Patrick Lankswert --- resource/csdk/stack/src/ocresource.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/resource/csdk/stack/src/ocresource.c b/resource/csdk/stack/src/ocresource.c index 95265bb..afffce3 100644 --- a/resource/csdk/stack/src/ocresource.c +++ b/resource/csdk/stack/src/ocresource.c @@ -788,6 +788,24 @@ HandleResourceWithEntityHandler (OCServerRequest *request, { OC_LOG(INFO, TAG, "Observation registration requested"); + ResourceObserver *obs = GetObserverUsingToken (request->requestToken, + request->tokenLength); + + if (obs) + { + OC_LOG (INFO, TAG, "Observer with this token already present"); + OC_LOG (INFO, TAG, "Possibly re-transmitted CON OBS request"); + OC_LOG (INFO, TAG, "Not adding observer. Not responding to client"); + OC_LOG (INFO, TAG, "The first request for this token is already ACKED."); + + // server requests are usually free'd when the response is sent out + // for the request in ocserverrequest.c : HandleSingleResponse() + // Since we are making an early return and not responding, the server request + // needs to be deleted. + FindAndDeleteServerRequest (request); + return OC_STACK_OK; + } + result = GenerateObserverId(&ehRequest.obsInfo.obsId); VERIFY_SUCCESS(result, OC_STACK_OK); -- 2.7.4