Skip to content

UDP connect() does not auto‑bind the socket, so subsequent send() fails with NOTCONN #6152

@artemyarulin

Description

@artemyarulin

In WASIX, calling sock_connect on a UDP socket should auto‑bind the socket to an ephemeral local port (POSIX behavior). Currently the internal auto‑bind creates a new socket but does not upgrade the inode, so the socket remains a PreSocket. As a result, send() on a UDP socket after connect() returns NOTCONN, breaking common UDP client patterns (DNS, statsd, syslog, etc.).

#include <arpa/inet.h>
#include <errno.h>
#include <stdio.h>
#include <sys/socket.h>

int main() {
  int s=socket(AF_INET,SOCK_DGRAM,0);
  struct sockaddr_in a={.sin_family=AF_INET,.sin_port=htons(7)};
  inet_pton(AF_INET,"127.0.0.1",&a.sin_addr);
  connect(s,(void*)&a,sizeof(a));
  // BUG: send() returns -1 with errno=ENOTCONN after successful connect()
  printf("send=%d errno=%d\n",(int)send(s,"x",1,0),errno);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions