Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_mosquitto_socketpair(...) call generally fails (Windows) #19

Closed
ralight opened this issue Mar 15, 2016 · 0 comments
Closed

_mosquitto_socketpair(...) call generally fails (Windows) #19

ralight opened this issue Mar 15, 2016 · 0 comments

Comments

@ralight
Copy link
Contributor

ralight commented Mar 15, 2016

migrated from Bugzilla #484693
status RESOLVED severity normal in component Mosquitto for 1.4
Reported in version 1.4 on platform PC
Assigned to: Roger Light

On 2015-12-18 09:50:15 -0500, Steve Woods wrote:

The creation of the socket pair from _mosquitto_connect_init(..) fails 95% of the time as the spW = accept(...) nearly always fails with WSAEWOULDBLOCK (Resource temporarily unavailable). This means that most of the time post's are delayed by an average of 500ms. Removing the non block call to the listen socket, fixes this behaviour. See git diff below (Also has some fixes for leaks if certain phases fail)

diff --git a/lib/net_mosq.c b/lib/net_mosq.c
index 0117ea1..8e9888e 100644
--- a/lib/net_mosq.c
+++ b/lib/net_mosq.c
@@ -1125,10 +1125,6 @@ int _mosquitto_socketpair(mosq_sock_t *pairR, mosq_sock_t *pairW)
continue;
}

  • if(_mosquitto_socket_nonblock(listensock)){
    
  •     continue;
    

- }

  if(family[i] == AF_INET){
      sa->sin_family = family[i];
      sa->sin_addr.s_addr = htonl(INADDR_LOOPBACK);

@@ -1146,12 +1142,11 @@ int _mosquitto_socketpair(mosq_sock_t *pairR, mosq_sock_t *pairW)
}
if(_mosquitto_socket_nonblock(spR)){
COMPAT_CLOSE(listensock);

  •     COMPAT_CLOSE(spR);
      continue;
    

    }
    if(connect(spR, (struct sockaddr *)&ss, ss_len) < 0){
    -#ifdef WIN32
    errno = WSAGetLastError();
    -#endif
    if(errno != EINPROGRESS && errno != COMPAT_EWOULDBLOCK){
    COMPAT_CLOSE(spR);
    COMPAT_CLOSE(listensock);
    @@ -1160,18 +1155,14 @@ int _mosquitto_socketpair(mosq_sock_t *pairR, mosq_sock_t *pairW)
    }
    spW = accept(listensock, NULL, 0);
    if(spW == -1){
    -#ifdef WIN32

  •     errno = WSAGetLastError();
    

    -#endif

  •     if(errno != EINPROGRESS && errno != COMPAT_EWOULDBLOCK){
    
  •         COMPAT_CLOSE(spR);
    
  •         COMPAT_CLOSE(listensock);
    
  •         continue;
    
  •     }
    
  •     COMPAT_CLOSE(spR);
    
  •     COMPAT_CLOSE(listensock);
    
  •     continue;
    

    }

    if(_mosquitto_socket_nonblock(spW)){
    COMPAT_CLOSE(spR);

  •     COMPAT_CLOSE(spW);
      COMPAT_CLOSE(listensock);
      continue;
    

    }

On 2015-12-18 17:03:01 -0500, Roger Light wrote:

It took a long time to replicate this, I see failures very very rarely. The problem that I see is down to _mosquitto_socket_nonblock() failing because the accept() call is incomplete - although that shouldn't matter in reality. Either way, not setting listensock as non-blocking does seem to fix it.

Thanks for the report.

On 2015-12-18 17:12:12 -0500, Roger Light wrote:

*** Bug 479143 has been marked as a duplicate of this bug. ***

@ralight ralight closed this as completed Mar 15, 2016
@lock lock bot locked as resolved and limited conversation to collaborators Aug 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant