diff --git a/CHANGELOG.md b/CHANGELOG.md index c16869c..9089a81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed main loop to keep calling svc_alive_task during a cloud disconnect and retry - change svc alive back to a separate thread. Shut it down with pthread_cond_timedwait - Refactored Upsteam RETRIEVE flow +- Fix re-registration to call nn_shutdown and nn_close, so we don't lose a socket. ## [1.0.1] - 2018-07-18 ### Added diff --git a/src/upstream.c b/src/upstream.c index dea551d..1046689 100644 --- a/src/upstream.c +++ b/src/upstream.c @@ -251,8 +251,10 @@ void *processUpstreamMessage() parStrncpy(temp->url,msg->u.reg.url, sizeof(temp->url)); if(nn_shutdown(temp->sock, 0) < 0) { - ParodusError ("Failed to shutdown\n"); + ParodusError ("nn_shutdown socket=%d err=%d\n", + temp->sock, errno); } + nn_close (temp->sock); temp->sock = nn_socket(AF_SP,NN_PUSH ); if(temp->sock >= 0) @@ -270,7 +272,7 @@ void *processUpstreamMessage() } else { - ParodusInfo("Client registered before. Sending acknowledgement \n"); + ParodusInfo("Client registered before. Sending ack on socket %d\n", temp->sock); status =sendAuthStatus(temp); if(status == 0) diff --git a/tests/test_upstream.c b/tests/test_upstream.c index f1601b4..b44285d 100644 --- a/tests/test_upstream.c +++ b/tests/test_upstream.c @@ -215,6 +215,13 @@ int nn_shutdown (int s, int how) return (int)mock(); } +int nn_close (int s) +{ + UNUSED(s); + function_called(); + return (int)mock(); +} + int nn_setsockopt (int s, int level, int option, const void *optval, size_t optvallen) { UNUSED(s); UNUSED(level); UNUSED(option); UNUSED(optval); UNUSED(optvallen); @@ -448,6 +455,9 @@ void test_processUpstreamMessageRegMsg() will_return(nn_shutdown, 1); expect_function_call(nn_shutdown); + will_return(nn_close, 0); + expect_function_call(nn_close); + will_return(nn_socket, 1); expect_function_call(nn_socket); @@ -607,12 +617,18 @@ void err_processUpstreamMessageRegMsg() will_return(nn_shutdown, -1); expect_function_call(nn_shutdown); + will_return(nn_close, 0); + expect_function_call(nn_close); + will_return(nn_socket, -1); expect_function_call(nn_socket); will_return(nn_shutdown, 1); expect_function_call(nn_shutdown); + will_return(nn_close, 0); + expect_function_call(nn_close); + will_return(nn_socket, 1); expect_function_call(nn_socket);