Skip to content

afpd: reap idle Spotlight queries to prevent resource leaks#2901

Merged
andylemin merged 1 commit intomainfrom
rdmark-reap-spotlight
Apr 19, 2026
Merged

afpd: reap idle Spotlight queries to prevent resource leaks#2901
andylemin merged 1 commit intomainfrom
rdmark-reap-spotlight

Conversation

@rdmark
Copy link
Copy Markdown
Member

@rdmark rdmark commented Apr 19, 2026

Clients that disconnect or crash without sending closeQueryForContext leave server-side query objects allocated indefinitely. Add a MAX_SL_QUERY_IDLE_TIME (60 s) constant and slq_idle_cleanup(), which scans the active query list on every Spotlight RPC and cancels or destroys any query not polled within the idle window.

The idle timer (slq_time) is reset on each fetchQueryResultsForContext call so actively-polled queries are not reaped. The cleanup runs alongside the existing slq_cancelled_cleanup() in afp_spotlight_rpc().

@augmentcode
Copy link
Copy Markdown

augmentcode bot commented Apr 19, 2026

🤖 Augment PR Summary

Summary: This PR prevents Spotlight query objects in afpd from leaking when clients disconnect/crash without closing their query contexts.

Changes:

  • Adds MAX_SL_QUERY_IDLE_TIME (60s) as an idle window for active queries.
  • Introduces slq_idle_cleanup() to scan sl_queries on every Spotlight RPC and reap idle queries.
  • Reaps queries by destroying finished/error queries and cancelling running queries.
  • Resets slq_time on fetchQueryResultsForContext so actively-polled queries are not timed out.
  • Runs slq_idle_cleanup() alongside the existing slq_cancelled_cleanup() in afp_spotlight_rpc().

🤖 Was this summary useful? React with 👍 or 👎

Copy link
Copy Markdown

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 2 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Comment thread etc/afpd/spotlight.c Outdated
Comment thread etc/afpd/spotlight.c
Clients that disconnect or crash without sending closeQueryForContext
leave server-side query objects allocated indefinitely. Add a
MAX_SL_QUERY_IDLE_TIME (60 s) constant and slq_idle_cleanup(), which
scans the active query list on every Spotlight RPC and cancels or
destroys any query not polled within the idle window.

The idle timer (slq_time) is reset on each fetchQueryResultsForContext
call so actively-polled queries are not reaped. The cleanup runs
alongside the existing slq_cancelled_cleanup() in afp_spotlight_rpc().
@rdmark rdmark force-pushed the rdmark-reap-spotlight branch from 42234e9 to 4f5fddc Compare April 19, 2026 06:19
@sonarqubecloud
Copy link
Copy Markdown

@github-actions
Copy link
Copy Markdown
Contributor

🔥 Spectest (AFP 3.4) - Flamegraph (AFP_ASSERT active)

Commit: 4f5fddcd9e2c3460750ab168a48f51a39cde367e
Profiling: On-CPU sampling @ 1009 Hz (prime), DWARF call-graph, x86_64
Build: debugoptimized (-O2 -g -fno-omit-frame-pointer)
Total Runtime: 67s, Netatalk Code-time: 7.5%,
Stacks: 1229, SVG size: 784K

🔥 Open interactive Flamegraph (SVG)

Flamegraph preview

📥 Download from artifacts →

🔝 Top 10 leaf functions
Function Samples
_raw_spin_unlock_irqrestore 353815560
do_syscall_64 133795800
__cp_end 75322080
dircache_remove_children 68384520
srso_alias_safe_ret 50545080
__syscall_cp_c 26759160
dircache_process_deferred_chain 25768080
finish_task_switch.isra.0 24777000
tcp_clean_rtx_queue.constprop.0 21803760
x64_sys_call 20812680

@rdmark rdmark requested a review from andylemin April 19, 2026 06:48
@andylemin andylemin merged commit c224241 into main Apr 19, 2026
55 checks passed
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