Document known gap: storeall doesn't wait for the app's own background threads

InitServlet.destroy() now holds incoming requests and waits (briefly) for
HttpController's request count to hit zero before calling
Registry.storeAll() - but that counter only tracks threads servicing HTTP
requests. A thread the webapp spun up itself (e.g. the order schedulers
InitServlet.init() starts) isn't tracked by it at all, and can still be
running - and still writing - while storeall takes its snapshot.

storeAll()'s synchronization still keeps this from corrupting the DB, and
stopwaitsecs=300 (sportrum-ansible) still keeps supervisord from killing
Tomcat mid-write - neither of those is undone by this. But a write from an
untracked background thread can still land after storeall's pass and
never get persisted. Properly closing it needs a real thread manager in
the webapp that can halt everything it started, not just hold new
requests. Noting it here, next to the code that currently doesn't do that,
so it isn't forgotten before that manager exists.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tj4SF2BGFxgoRYrCAzNpDb
This commit is contained in:
Claude 2026-10-01 09:37:31 +00:00
parent 72b159c997
commit a34ea9a9bc
No known key found for this signature in database

View file

@ -68,6 +68,28 @@ case "$mode" in
;; ;;
esac esac
# KNOWN GAP (2026-10-01): storeall is not actually guaranteed to see a
# fully quiesced app at the moment it runs. InitServlet.destroy() calls
# HttpController.setRequestsOnHold(true) and waits (up to 2s) for
# HttpController.getRequestCount() to hit zero before calling
# icp.Registry.storeAll() - but that only tracks threads servicing
# incoming HTTP requests through HttpController. Any background thread the
# webapp itself started (e.g. the order schedulers InitServlet.init() spins
# up - see "Starting order schedulers" in InitServlet.java) is invisible to
# that counter and can still be running, and potentially still mutating
# state, while storeall takes its snapshot. storeAll()'s own
# synchronization keeps this from corrupting the DB, but a write from one
# of these threads can still land after storeall's pass and never get
# persisted before shutdown.
#
# Not fixed by anything in this script or by Tomcat's stopwaitsecs (see
# sportrum-ansible's supervisord.conf) - that only protects storeall
# itself from being killed mid-write, it does nothing about threads other
# than the app's own request-handling threads. Properly closing this needs
# a real thread manager in the webapp that can be told to halt (or at
# least pause/join) every thread it started, not just hold new requests,
# called from InitServlet.destroy() before storeAll() runs. Not
# implemented yet - noted here so it isn't forgotten.
running=$(./tomcat_ctl.sh status | grep "tomcat8 is stopped") running=$(./tomcat_ctl.sh status | grep "tomcat8 is stopped")
if [ "x$running" == "x" ]; then if [ "x$running" == "x" ]; then
printf "Call server command storeall.."; sleep 2 printf "Call server command storeall.."; sleep 2