Giter Club home page Giter Club logo

Comments (5)

gmwiz avatar gmwiz commented on June 30, 2024 1

I was able to further narrow it down, and create a simple C reproducer that demonstrates the issue. It seems as if MongoDB Unix-domain sockets are marked non-blocking, and then epoll_wait is used to wait for a new client (before calling accept). It also seems like MongoDB uses epoll_ctl to track the socket, and it does so immediately after creating the socket, and before calling bind on the socket. When re-ordering the calls, moving the epoll_ctl call after bind, everything seems to work perfectly. I'm not entirely certain what component in the gVisor code base is responsible for this, but I'll try and take a look.

#define _GNU_SOURCE
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/epoll.h>


int main(int argc, char *argv[]) {
    int sock_fd = -1;
    int flags = 0;
    int ret = -1;
    int client_fd = -1;
    int epoll_fd = -1;
    struct epoll_event epoll_read = {
        .events = EPOLLIN|EPOLLPRI|EPOLLERR|EPOLLHUP|EPOLLET,
    };
    struct sockaddr_un addr = {0};
    char *sock_path = NULL;
    char *msg = NULL;

    if (argc < 3) {
        printf("<socket_path> <msg>\n");
        return 1;
    }

    sock_path = argv[1];
    msg = argv[2];

    epoll_fd = epoll_create1(EPOLL_CLOEXEC);
    if (epoll_fd < 0) {
        perror("epoll_create");
        return 1;
    }

    printf("socket\n");
    sock_fd = socket(AF_UNIX, SOCK_STREAM|SOCK_NONBLOCK, 0);
    if (sock_fd < 0) {
        perror("socket");
        return 1;
    }

    if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, sock_fd, &epoll_read) < 0) {
        perror("epoll_ctl");
        return 1;
    }

    printf("bind\n");
    unlink(sock_path);
    addr.sun_family = AF_UNIX;
    strcpy(addr.sun_path, sock_path);
    if (bind(sock_fd, &addr, sizeof(addr)) < 0) {
        perror("bind");
        return 1;
    }

    printf("listen\n");
    if (listen(sock_fd, 128) < 0) {
        perror("listen");
        return 1;
    }

    do {
        struct epoll_event ev[128] = {0};
        ret = epoll_wait(epoll_fd, ev, 128, -1);
    } while (ret < 0 && errno == EINTR);

    if (ret <= 0) {
        perror("epoll_wait");
        return 1;
    }

    printf("accept\n");
    client_fd = accept(sock_fd, NULL, NULL);
    if (client_fd < 0) {
        perror("accept");
        return 1;
    }

    printf("send: %s\n", msg);
    send(client_fd, msg, strlen(msg), 0);
    
    printf("done!\n");
    return 0;
}

from gvisor.

gmwiz avatar gmwiz commented on June 30, 2024 1

Hi @ayushr2
Thank you so much for the super fast fix!!! That's amazing!
Do you happen to have an estimation of when will this patch be included in the next official release?
TIA

from gvisor.

ayushr2 avatar ayushr2 commented on June 30, 2024

Thanks for the bug report, and for narrowing it down with the reproducer. That was really helpful.

I think I have fixed the issue in #9849. Lets see if the e2e test concur.

from gvisor.

ayushr2 avatar ayushr2 commented on June 30, 2024

Hoping to have a release on Jan 3rd. cc @manninglucas

from gvisor.

ayushr2 avatar ayushr2 commented on June 30, 2024

Ah, we released the Monday candidate (which doesn't contain the fix). You can expect us to make a release for 01/08 candidate next Wednesday.

from gvisor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.