Skip to content

HTTPDownload: bound libcurl connect-phase via GetNativeHandle() - #565

Merged
mrjimenez merged 1 commit into
amule-project:masterfrom
got3nks:feature/httpdownload-curlopt-tuning
May 11, 2026
Merged

HTTPDownload: bound libcurl connect-phase via GetNativeHandle()#565
mrjimenez merged 1 commit into
amule-project:masterfrom
got3nks:feature/httpdownload-curlopt-tuning

Conversation

@got3nks

@got3nks got3nks commented May 10, 2026

Copy link
Copy Markdown
Contributor

Summary

CHTTPDownloadThread sets CURLOPT_NOSIGNAL=1 and CURLOPT_CONNECTTIMEOUT_MS=30000 on the underlying CURL* (via wxWebRequest::GetNativeHandle(), public wx API since 3.2.0) immediately after CreateRequest, before Start(). Bounds the UI/EC freeze when wxWebRequest's libcurl backend (Linux/*BSD only) tries to reach an unreachable HTTPS endpoint — the connect phase now gives up after 30 s instead of waiting the kernel's full TCP-SYN retry sequence (~2 min) or libcurl's default 300 s timeout.

Fix

Three small pieces, all gated by #if wxUSE_WEBREQUEST_CURL so non-curl backends compile unchanged:

  • src/HTTPDownload.cpp — after CreateRequest, fetch the native CURL* and curl_easy_setopt the two options.
  • cmake/wx.cmake — soft find_package(CURL) on Linux/*BSD; if libcurl headers are absent the patch silently no-ops and a configure-time STATUS line tells the developer how to enable it.
  • src/CMakeLists.txt — single foreach adds the CURL include + link to whichever of amule / amuled / amulegui exist in the configured build.

Caveats

Does not close libcurl's threaded-resolver pthread_join hang in curl_easy_cleanup() — that requires either libcurl built with --enable-ares (out of our control on Ubuntu's default libcurl) or a real DNS timeout under 30 s. This patch bounds the visible window for the common-case unreachable-endpoint scenario.

macOS (NSURLSession backend) and Windows (WinHTTP backend) are unaffected by both the bug and this fix.

CHTTPDownloadThread sets CURLOPT_NOSIGNAL=1 and
CURLOPT_CONNECTTIMEOUT_MS=30000 on the underlying CURL* (via
wxWebRequest::GetNativeHandle, public wx API since 3.2.0) immediately
after CreateRequest, before Start().

Bounds the UI/EC freeze when wxWebRequest's libcurl backend (Linux/*BSD
only) tries to reach an unreachable HTTPS endpoint (captive portal,
blocked TCP route, non-routable IP) — the connect phase now gives up
after 30 s instead of waiting the kernel's full TCP-SYN retry sequence
(~2 min) or libcurl's default 300 s timeout.

Does not close libcurl's threaded-resolver pthread_join hang in
curl_easy_cleanup() (that needs either libcurl built with --enable-ares
or a real DNS timeout under 30 s); bounds the visible window for the
common-case unreachable-endpoint scenario.

Mac (NSURLSession backend) and Windows (WinHTTP backend) are unaffected
by both the bug and this fix; #if wxUSE_WEBREQUEST_CURL gates the new
code so non-curl backends compile unchanged. find_package(CURL) is
soft-required on Linux/*BSD; if libcurl-dev is absent the patch silently
no-ops and a configure-time STATUS line tells the developer how to enable
it.
@got3nks
got3nks force-pushed the feature/httpdownload-curlopt-tuning branch from e029c9b to a83824a Compare May 10, 2026 10:20
@mrjimenez
mrjimenez merged commit 8bf7a6a into amule-project:master May 11, 2026
12 checks passed
@got3nks
got3nks deleted the feature/httpdownload-curlopt-tuning branch May 11, 2026 08:00
got3nks added a commit to got3nks/amule that referenced this pull request Jul 23, 2026
…mule-project#565)

Fix the CMake wiring so mmap is actually reachable (amule-project#34): the port never
set HAVE_MMAP (glib21.cmake probed munmap, not mmap) and never passed
ENABLE_MMAP to the compiler, so USE_MMAP was dead on every CMake build even
with -DENABLE_MMAP=YES. Add the missing mmap/sigaction probes and a single
MMAP_SUPPORTED capability macro (set when mmap/munmap/sysconf/_SC_PAGESIZE/
sigaction are all present) gating the code path, the preferences checkbox and
the EC tag. ENABLE_MMAP becomes a default-ON build opt-out (no external
dependency; all libc).

Make mmap use a runtime preference (MMapEnabled, default OFF):
- CFileArea reads an atomic flag at ReadAt/StartWriteAt; the per-area mode is
  captured in m_mmap_buffer so FlushAt/Close stay state-driven -- safe to flip
  live with active downloads and uploads (in-flight blocks finish in their
  original mode).
- The SIGSEGV/SIGBUS recovery handler installs once, when mmap is first
  enabled, rather than per read/write and never when off, so it cannot collide
  with sanitizers/debuggers/crash reporters.
- Advanced-tab checkbox; capability negotiated over EC (EC_TAG_FILES_MMAP_
  SUPPORTED/_ENABLED) so amulegui/amulecmd/amuleweb/amuleapi show the toggle
  only when the connected daemon supports mmap (tag-presence == capability;
  works cross-platform, e.g. Windows GUI to a Linux daemon).

Relax the 4 GiB per-area cap (forum 16444): it only guards a 32-bit off_t.
On 64-bit off_t -- every modern LFS build, including 32-bit-with-LFS (aMule
inherits _FILE_OFFSET_BITS=64 from wx) -- mmap handles large offsets natively,
verified against a >4 GiB region, so large files get mmap for their whole
length; the cap remains only for a (wx-precluded) non-LFS 32-bit build.
got3nks added a commit to got3nks/amule that referenced this pull request Jul 23, 2026
…-project#566)

Follow-up to amule-project#565: surface the memory-mapped file I/O preference on the REST
API. files.mmap_supported is a read-only daemon capability (mirrors
upnp_available), read from the EC_TAG_FILES_MMAP_SUPPORTED tag; files.mmap_enabled
is the runtime value. A PATCH that sets mmap_enabled is rejected with 409 when the
connected daemon lacks mmap support, so the option is only writable against a core
that can actually use it.

Updates docs/api/REFERENCE.md and the 15-preferences-patch curl smoke (round-trip
on a mmap-capable daemon; the 409 capability gate otherwise).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants