Skip to content

Commit

Permalink
fix(el): Treat some accept() errors as temporary
Browse files Browse the repository at this point in the history
If accept() fails, some of the error codes indicate failure with the
incoming connection, not the server socket. Do not kill the server
socket if one of those error codes are detected.
  • Loading branch information
teijokinnunen authored and jpfr committed Oct 16, 2024
1 parent 1953451 commit 988fa7c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions arch/eventloop_posix/eventloop_posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,16 @@ typedef SSIZE_T ssize_t;
#define UA_AGAIN EAGAIN /* the same as wouldblock on nearly every system */
#define UA_INPROGRESS WSAEINPROGRESS
#define UA_WOULDBLOCK WSAEWOULDBLOCK
#define UA_CONNRESET WSAECONNRESET
#define UA_NOBUFS WSAENOBUFS
#define UA_MFILE WSAEMFILE
#define UA_POLLIN POLLRDNORM
#define UA_POLLOUT POLLWRNORM
#define UA_SHUT_RDWR SD_BOTH

#define UA_IS_TEMPORARY_ACCEPT_ERROR(err) \
((err) == UA_INTERRUPTED || (err) == UA_CONNRESET || (err) == UA_NOBUFS || (err) == UA_MFILE)

#define UA_getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) \
getnameinfo(sa, (socklen_t)salen, host, (DWORD)hostlen, serv, (DWORD)servlen, flags)
#define UA_poll(fds,nfds,timeout) WSAPoll((LPWSAPOLLFD)fds, nfds, timeout)
Expand Down Expand Up @@ -136,10 +142,17 @@ typedef int SOCKET;
#define UA_AGAIN EAGAIN /* the same as wouldblock on nearly every system */
#define UA_INPROGRESS EINPROGRESS
#define UA_WOULDBLOCK EWOULDBLOCK
#define UA_CONNABORTED ECONNABORTED
#define UA_MFILE EMFILE
#define UA_NFILE ENFILE
#define UA_NOBUFS ENOBUFS
#define UA_POLLIN POLLIN
#define UA_POLLOUT POLLOUT
#define UA_SHUT_RDWR SHUT_RDWR

#define UA_IS_TEMPORARY_ACCEPT_ERROR(err) \
((err) == UA_INTERRUPTED || (err) == UA_CONNABORTED || (err) == UA_MFILE || (err) == UA_NFILE || (err) == UA_NOBUFS)

#define UA_getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) \
getnameinfo(sa, salen, host, hostlen, serv, servlen, flags)
#define UA_poll poll
Expand Down
2 changes: 1 addition & 1 deletion arch/eventloop_posix/eventloop_posix_tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ TCP_listenSocketCallback(UA_ConnectionManager *cm, TCP_FD *conn, short event) {
UA_FD newsockfd = accept(conn->rfd.fd, (struct sockaddr*)&remote, &remote_size);
if(newsockfd == UA_INVALID_FD) {
/* Temporary error -- retry */
if(UA_ERRNO == UA_INTERRUPTED)
if(UA_IS_TEMPORARY_ACCEPT_ERROR(UA_ERRNO))
return;

/* Close the listen socket */
Expand Down

0 comments on commit 988fa7c

Please sign in to comment.