@@ -96,7 +96,7 @@ static char cdb2_machine_room[16] = "";
9696#define CDB2_PORTMUXPORT_DEFAULT 5105
9797static int CDB2_PORTMUXPORT = CDB2_PORTMUXPORT_DEFAULT ;
9898
99- #define MAX_RETRIES_DEFAULT 21
99+ #define MAX_RETRIES_DEFAULT 20
100100static int MAX_RETRIES = MAX_RETRIES_DEFAULT ; /* We are looping each node twice. */
101101
102102#define MIN_RETRIES_DEFAULT 16
@@ -596,7 +596,7 @@ enum {
596596 PASSFD_SENDMSG = -7 /* error with sendmsg() */
597597};
598598
599- static int recv_fd_int (int sockfd , void * data , size_t nbytes , int * fd_recvd )
599+ static int recv_fd_int (int sockfd , void * data , size_t nbytes , int * fd_recvd , int timeoutms )
600600{
601601 ssize_t rc ;
602602 size_t bytesleft ;
@@ -617,6 +617,21 @@ static int recv_fd_int(int sockfd, void *data, size_t nbytes, int *fd_recvd)
617617 bytesleft = nbytes ;
618618
619619 while (bytesleft > 0 ) {
620+ if (timeoutms > 0 ) {
621+ struct pollfd pol ;
622+ int pollrc ;
623+ pol .fd = sockfd ;
624+ pol .events = POLLIN ;
625+ pollrc = poll (& pol , 1 , timeoutms );
626+
627+ if (pollrc == 0 ) {
628+ return PASSFD_TIMEOUT ;
629+ } else if (pollrc == -1 ) {
630+ /* error will be in errno */
631+ return PASSFD_POLL ;
632+ }
633+ }
634+
620635#ifdef HAVE_MSGHDR_MSG_CONTROL
621636 msg .msg_control = control_un .control ;
622637 msg .msg_controllen = sizeof (control_un .control );
@@ -695,7 +710,7 @@ static int recv_fd_int(int sockfd, void *data, size_t nbytes, int *fd_recvd)
695710static int recv_fd (int sockfd , void * data , size_t nbytes , int * fd_recvd )
696711{
697712 int rc ;
698- rc = recv_fd_int (sockfd , data , nbytes , fd_recvd );
713+ rc = recv_fd_int (sockfd , data , nbytes , fd_recvd , 0 );
699714 if (rc != 0 && * fd_recvd != -1 ) {
700715 int errno_save = errno ;
701716 if (close (* fd_recvd ) == -1 ) {
@@ -2496,13 +2511,17 @@ static int cdb2portmux_get(cdb2_hndl_tp *hndl, const char *type,
24962511 hndl -> connect_timeout );
24972512 if (fd < 0 ) {
24982513 debugprint ("cdb2_tcpconnecth_to returns fd=%d'\n" , fd );
2499- snprintf (
2500- hndl -> errstr , sizeof (hndl -> errstr ),
2501- "%s:%d Can't connect to portmux port dbname: %s tier: %s host: %s "
2502- "port %d. "
2503- "Err(%d): %s. Portmux down on remote machine or firewall issue." ,
2504- __func__ , __LINE__ , instance , type , remote_host , CDB2_PORTMUXPORT ,
2505- errno , strerror (errno ));
2514+ if (errno == EINPROGRESS ) {
2515+ snprintf (hndl -> errstr , sizeof (hndl -> errstr ),
2516+ "%s:%d Can't connect to portmux dbname: %s tier: %s host: %s port %d. "
2517+ "Err(%d): %s. Firewall or connect timeout issue." ,
2518+ __func__ , __LINE__ , instance , type , remote_host , CDB2_PORTMUXPORT , errno , strerror (errno ));
2519+ } else {
2520+ snprintf (hndl -> errstr , sizeof (hndl -> errstr ),
2521+ "%s:%d Can't connect to portmux dbname: %s tier: %s host: %s port %d. "
2522+ "Err(%d): %s. Invalid remote machine or portmux down on remote machine." ,
2523+ __func__ , __LINE__ , instance , type , remote_host , CDB2_PORTMUXPORT , errno , strerror (errno ));
2524+ }
25062525 port = -1 ;
25072526 goto after_callback ;
25082527 }
@@ -2882,16 +2901,16 @@ static void clear_responses(cdb2_hndl_tp *hndl)
28822901 cdb2__sqlresponse__free_unpacked (hndl -> lastresponse , hndl -> allocator );
28832902 if (hndl -> protobuf_size )
28842903 hndl -> protobuf_offset = 0 ;
2904+ hndl -> lastresponse = NULL ;
28852905 free ((void * )hndl -> last_buf );
28862906 hndl -> last_buf = NULL ;
2887- hndl -> lastresponse = NULL ;
28882907 }
28892908
28902909 if (hndl -> firstresponse ) {
28912910 cdb2__sqlresponse__free_unpacked (hndl -> firstresponse , NULL );
2911+ hndl -> firstresponse = NULL ;
28922912 free ((void * )hndl -> first_buf );
28932913 hndl -> first_buf = NULL ;
2894- hndl -> firstresponse = NULL ;
28952914 }
28962915}
28972916
@@ -3575,9 +3594,9 @@ int cdb2_get_effects(cdb2_hndl_tp *hndl, cdb2_effects_tp *effects)
35753594 effects -> num_deleted = hndl -> firstresponse -> effects -> num_deleted ;
35763595 effects -> num_inserted = hndl -> firstresponse -> effects -> num_inserted ;
35773596 cdb2__sqlresponse__free_unpacked (hndl -> firstresponse , NULL );
3597+ hndl -> firstresponse = NULL ;
35783598 free ((void * )hndl -> first_buf );
35793599 hndl -> first_buf = NULL ;
3580- hndl -> firstresponse = NULL ;
35813600 rc = 0 ;
35823601 } else {
35833602 rc = -1 ;
@@ -3696,6 +3715,7 @@ int cdb2_close(cdb2_hndl_tp *hndl)
36963715
36973716 if (hndl -> firstresponse ) {
36983717 cdb2__sqlresponse__free_unpacked (hndl -> firstresponse , NULL );
3718+ hndl -> firstresponse = NULL ;
36993719 free ((void * )hndl -> first_buf );
37003720 hndl -> first_buf = NULL ;
37013721 }
@@ -3704,7 +3724,9 @@ int cdb2_close(cdb2_hndl_tp *hndl)
37043724 cdb2__sqlresponse__free_unpacked (hndl -> lastresponse , hndl -> allocator );
37053725 if (hndl -> protobuf_size )
37063726 hndl -> protobuf_offset = 0 ;
3727+ hndl -> lastresponse = NULL ;
37073728 free ((void * )hndl -> last_buf );
3729+ hndl -> last_buf = NULL ;
37083730 }
37093731
37103732 if (hndl -> protobuf_data )
@@ -7258,6 +7280,7 @@ int cdb2_unregister_event(cdb2_hndl_tp *hndl, cdb2_event *event)
72587280{
72597281 cdb2_event * curr , * prev ;
72607282
7283+ /* no-op on null. */
72617284 if (event == NULL )
72627285 return 0 ;
72637286
@@ -7267,7 +7290,7 @@ int cdb2_unregister_event(cdb2_hndl_tp *hndl, cdb2_event *event)
72677290 curr != NULL && curr != event ; prev = curr , curr = curr -> next )
72687291 ;
72697292 if (curr != event ) {
7270- pthread_mutex_lock (& cdb2_event_mutex );
7293+ pthread_mutex_unlock (& cdb2_event_mutex );
72717294 return EINVAL ;
72727295 }
72737296 prev -> next = curr -> next ;
0 commit comments