]> git.proxmox.com Git - mirror_kronosnet.git/commitdiff
[udp] fix incorrect return code
authorFabio M. Di Nitto <fdinitto@redhat.com>
Tue, 17 Oct 2017 14:36:53 +0000 (16:36 +0200)
committerFabio M. Di Nitto <fdinitto@redhat.com>
Thu, 19 Oct 2017 04:39:32 +0000 (06:39 +0200)
UDP TX is tricky and racy and in theory TX never fails, as UDP is allowed
to drop packets internally anyway.

In some race condition situations, we can endup in a situation where:
- thread X attempts to send a packet
- socket receives an ICMP back (for whatever reasons) generated
  by some other random thread/packet combo
- thread X detects an error in TX and decode the error (correct)

pre patch:
- thread X would treat that as error and drop the packet
post patch:
- thread X should simply resend the packet

simply also the ordering of parsing socket error code to make it easier to read

Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
libknet/transport_udp.c

index 622a6532e004342bbf9a2b64f786e6aaffecf8ce..2c0a81cc8fb7f37ade4c6bd099c619fd567f4967 100644 (file)
@@ -357,18 +357,18 @@ static int udp_transport_rx_sock_error(knet_handle_t knet_h, int sockfd, int rec
 static int udp_transport_tx_sock_error(knet_handle_t knet_h, int sockfd, int recv_err, int recv_errno)
 {
        if (recv_err < 0) {
+               if (recv_errno == EMSGSIZE) {
+                       return 0;
+               }
                if ((recv_errno == ENOBUFS) || (recv_errno == EAGAIN)) {
 #ifdef DEBUG
                        log_debug(knet_h, KNET_SUB_TRANSP_UDP, "Sock: %d is overloaded. Slowing TX down", sockfd);
 #endif
                        usleep(KNET_THREADS_TIMERES / 16);
-                       return 1;
-               }
-               read_errs_from_sock(knet_h, sockfd);
-               if (recv_errno == EMSGSIZE) {
-                       return 0;
+               } else {
+                       read_errs_from_sock(knet_h, sockfd);
                }
-               return -1;
+               return 1;
        }
 
        return 0;