uNetworking / uNetworking/uSockets

us_listen_socket_close crashes with memory error

Open
#237 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
1.5k
Forks
307
PR merge metrics
No merged PRs in 30d

Description

Hi,

I followed the suggestion from ReadMe in order for the loop to exit gracefully.
However, after calling us_listen_socket_close(), the application exited the Exception thrown: read access violation. ls->s.context->**loop** was 0xFFFFFFFFFFFFFFB7.
This happens the next line after the call to the bsd_close_socket(us_poll_fd((struct us_poll_t *) &ls->s)) inside context.c.

I am using v0.8.8 with uWebSockets v20.71.0.
Visual studio 2022 Debug Mode with Vcpkg and Windows 11.

Thank you,

The code:

` us_listen_socket_t* socket;

std::thread t([&]()
    {
        std::this_thread::sleep_for(std::chrono::seconds(15));
        us_listen_socket_close(0, socket);
    });

uWS::App().get("/*", fileHandler)
    .listen(80, [&](auto* listen_socket) {
    if (listen_socket) {
        std::cout << "Listening on port " << 80 << '\n';
        socket = listen_socket;
    }
    else
    {
        std::cout << "server failed to launch";
    }
        }).run();`

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in context.c at us_listen_socket_close(), especially the bsd_close_socket(us_poll_fd((struct us_poll_t *) &ls->s)) call and the subsequent access to ls->context->loop. Reproduce the supplied uWS App().listen().run() flow with the delayed thread on Windows 11 using Visual Studio 2022, then verify that closing the listen socket exits gracefully without the reported read access violation.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, cpp
Domain
networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.