Solaris: API requests over keep-alive silently dropped — root cause (cheroot /dev/poll selector) + one-line fix

Report & discuss bugs found in SABnzbd
Forum rules
Help us help you:
  • Are you using the latest stable version of SABnzbd? Downloads page.
  • Tell us what system you run SABnzbd on.
  • Adhere to the forum rules.
  • Do you experience problems during downloading?
    Check your connection in Status and Interface settings window.
    Use Test Server in Config > Servers.
    We will probably ask you to do a test using only basic settings.
  • Do you experience problems during repair or unpacking?
    Enable +Debug logging in the Status and Interface settings window and share the relevant parts of the log here using [ code ] sections.
Post Reply
mongolc
Newbie
Newbie
Posts: 33
Joined: March 14th, 2018, 1:07 pm

Solaris: API requests over keep-alive silently dropped — root cause (cheroot /dev/poll selector) + one-line fix

Post by mongolc »

**Solaris: keep-alive API requests silently lost — root cause and one-line fix (cheroot + /dev/poll)**

Posting this for the handful of us running SABnzbd on Solaris/illumos, and because the fix belongs upstream in cheroot.

**Environment:** SABnzbd 5.1.2 from git, Python 3.11, cheroot 11.1.2, Solaris 11.4 x86. Same behaviour on 5.0.x.

**Symptom:** Any client that sends several API requests quickly over one keep-alive connection (NZBHydra2 batch adds, Sonarr/Radarr, a plain `requests.Session`) has one request silently vanish. First 2–3 succeed in ~10 ms, then one hangs for exactly 10 seconds and the client reports a timeout or "connection closed." With SABnzbd at log level Debug, the lost request never appears in the log at all — it never reached the request handler. A fresh connection immediately works again.

**Reproducer** (fails 100% on Solaris, never on Linux):

```
import requests, time
s = requests.Session()
for i in range(20):
t = time.time()
try:
r = s.post('http://SAB:PORT/api', data={'mode':'queue','output':'json','apikey':'KEY'}, timeout=12)
print(i+1, f'{time.time()-t:.3f}s', r.status_code)
except Exception as e:
print(i+1, f'{time.time()-t:.3f}s FAILED', type(e).__name__)
time.sleep(0.5)
```

Request #3 fails with `ConnectionError` after ~9.9 s (server closed the socket — not a client read timeout).

**Root cause:** cheroot parks idle keep-alive connections in `selectors.DefaultSelector()` (`cheroot/connections.py`, `_ThreadsafeSelector.__init__`) and re-dispatches a connection to a worker when the selector reports it readable. Worker threads register connections into that selector while the main loop is already blocked in `select()`. On Solaris, `selectors.DefaultSelector` resolves to `DevpollSelector` (`/dev/poll`), and in this pattern the readiness of a connection registered while a poll is in flight is not reported. The request is sitting in the socket buffer, the selector never wakes for it, the connection is treated as idle and reaped at CherryPy's `server.socket_timeout` (default 10 s) — which is exactly the 10-second hang. Linux resolves `DefaultSelector` to `EpollSelector` and never hits this.

**Fix:** force a plain level-triggered `poll(2)` selector. One line in the venv:

```
# cheroot/connections.py, in _ThreadsafeSelector.__init__
self._selector = selectors.PollSelector() # was: selectors.DefaultSelector()
```

After the change the reproducer runs 20/20 clean, and NZBHydra2 batch adds of a dozen NZBs all land instantly. It's been stable under sustained 120 MB/s downloads with two browsers, Sonarr, Radarr and Hydra all polling.

**Two related notes for anyone chasing the same thing:**

1. Patching `cheroot/server.py`'s `timeout = 10` class attribute does nothing — CherryPy overwrites it at startup from `server.socket_timeout`. I carried that "fix" for months believing it helped; it was a no-op.
2. SABnzbd doesn't set `server.thread_pool`, so CherryPy's default of 10 workers applies, and cheroot binds one worker per open connection for its lifetime. With two browsers + the *arr apps + Hydra's connection pool it's easy to exceed 10 and have new connections queue. Adding `"server.thread_pool": 30` to the `cherrypy.config.update()` dict in SABnzbd.py fixes that separately. Also, the `cherrypy_max_connections` option still present in older sabnzbd.ini files isn't read by 5.x at all.

Happy to open this against cheroot's tracker as well if the devs think that's the right home — it isn't a SABnzbd bug per se, but SABnzbd is where Solaris users will hit it. If a maintainer wants any additional traces from a Solaris box, say the word.
User avatar
sander
Release Testers
Release Testers
Posts: 9508
Joined: January 22nd, 2008, 2:22 pm

Re: Solaris: API requests over keep-alive silently dropped — root cause (cheroot /dev/poll selector) + one-line fix

Post by sander »

> Happy to open this against cheroot's tracker as well if the devs think that's the right hom

the git version of SABnzbd (5.2.0-dev) doesn't use cheroot / cherrypy anymore: switched to uvicorn / starlette.

So you could check how that behaves.
mongolc
Newbie
Newbie
Posts: 33
Joined: March 14th, 2018, 1:07 pm

Re: Solaris: API requests over keep-alive silently dropped — root cause (cheroot /dev/poll selector) + one-line fix

Post by mongolc »

sander wrote: September 8th, 2026, 2:05 am > Happy to open this against cheroot's tracker as well if the devs think that's the right hom

the git version of SABnzbd (5.2.0-dev) doesn't use cheroot / cherrypy anymore: switched to uvicorn / starlette.

So you could check how that behaves.
yeah? nice I'll start moving to that branch and see what I run into since I've had to do multiple different work arounds with PollSelector, thread_pool, the retired timeout, arguably the Glitter timeout so it works well in Solaris 11.4 anyway. thanks for replying.
mongolc
Newbie
Newbie
Posts: 33
Joined: March 14th, 2018, 1:07 pm

Re: Solaris: API requests over keep-alive silently dropped — root cause (cheroot /dev/poll selector) + one-line fix

Post by mongolc »

yeah this beta is highly successful on Solaris 11.4

sabctools 9.7.x switched to a CMake-based build. With no Solaris wheel, pip tried to bootstrap CMake itself from source — I killed it after 30 minutes of compiling libcurl. Fix: Oracle's cmake package plus pip install --no-build-isolation. That's the one that'll bite anyone on a platform without wheels.

cryptography needs Rust to build. Same trick as the original install: symlink Oracle's vendored copy into the venv.

orjson skipped as always (Rust); ujson fallback works fine.

httptools — the one new C extension — compiled cleanly with gcc 15, no drama.

great job on this! funny because I finally got 5.1.2 working perfectly with those cherry fixes as well..
Post Reply