uNetworking / uNetworking/uWebSockets
ASIO issues with uWS::Loop falling through with multiple Loops/threads
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 19k
- Forks
- 1.9k
- Avg merge
- 3h 24m
- Merged PRs (30d)
- 5
Description
I've explored a bit more after briefly filing before, and found there are (what seem to be) a few issues with ASIO as a backend (hopefully fixed one of them).
I'm happy to split this into separate bugs, but it may also be fairly related, and am looking for advice on what to dig into to try to resolve it. The issues:
- If I have two different threads, and each calls
uWS::App::Run, theRunwill not finish on either of the the threads, untilus_listen_socket_closeis called on both.- This can be seen when
TRIGGER_BOTH_APP_CLOSURES_BEFORE_BLOCKING_ON_EITHERis set to false in the repro case
- This can be seen when
- Even with no handlers set up or used for
uWS::App(i.e. nothing except the default timers going on), it waits 1 second before exiting afterus_listen_socket_close. I can work around this to shutdown more quickly (which matters since I'm doing this several times in a test) - by callingus_timer_setwith a faux 1ms timer. I assume there might be an easy proper fix, I just don't grok enough of what's going on yet.- This can be observed in the repro case by setting
TRIGGER_BOTH_APP_CLOSURES_BEFORE_BLOCKING_ON_EITHERto true (avoids the first issue), andACCELERATE_SHUTDOWN_WITH_FAUX_TIMERto false.
- This can be observed in the repro case by setting
- Sometimes the
uWS::App::Runnever falls through, when, in a loop, creating two threads and callinguWS::App::Runand then exiting withus_listen_socket_close. If I run it 500 times, I rarely ever succeed on all of them.- This can be seen with
TRIGGER_BOTH_APP_CLOSURES_BEFORE_BLOCKING_ON_EITHERset to true, andACCELERATE_SHUTDOWN_WITH_FAUX_TIMERset to true.
- This can be seen with
This is the repo case. Happy to investigate further, though a couple of suggestions of where to look will speed me up.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by compiling and repeatedly running the supplied uwebsockets_many_apps.cc reproduction, varying TRIGGER_BOTH_APP_CLOSURES_BEFORE_BLOCKING_ON_EITHER and ACCELERATE_SHUTDOWN_WITH_FAUX_TIMER. Trace uWS::App::Run, us_listen_socket_close, and the ASIO backend across both threads. Done means the reported blocking, one-second delay, and intermittent non-returning shutdowns are reproduced, explained, and covered by a reliable regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend, networking
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100