Repository navigation
Conversation
|
Colin's thoughts: High confidence. High benefit (timeouts are enforced). I think no risk -- I think the pre-existing behaviour was that a query that exceeded its timeout would still ultimately be cancelled before returning results, just not in a timely fashion. Followup idea: are there other areas in the code that have nested loops that may not enforce deadlines in a timely manner? |
|
Follow-up done (audit). I ran 4,000 fuzz queries against Generated by Claude Code |
|
Colin's thoughts: the followup change looks good. |
This PR helps attic queries by avoiding unnecessary memory copies. Passing the end iterator by reference avoids the copy. On a Nova Scotia full-history database: `[date:"2018-01-01T00:00:00Z"][out:xml]; rel(42,-67.6,47.5,-58); out body;` dropped from 19.0 s to 11.7 s on my computer, with identical output.
7febffa to
8101b72
Compare
|
Offered upstream in fossgis#12 |
546cd29 to
db29404
Compare
The expensive around filters (filter_nodes_expensive, filter_ways_expensive, filter_relations_expensive) ran to completion before the next health check. A slow around therefore kept a CPU busy long after the query's [timeout:] had passed, only to fail with the timeout error once it finished. A Periodic_Health_Check now calls rman.health_check after every 64k units of work, so the query stops with the usual timeout error soon after its time is up. A unit is about one comparison of a candidate's point or segment with a point or segment of the input: is_inside on a way geometry now takes the check and ticks it for every point and segment it tests, also for the ways of candidate relations. Counting candidates alone isn't enough, because a single long way, such as a power line, tested against a large input can take seconds. Queries that finish within their limits return the same results as before. Co-Authored-By: Colin Dellow <cldellow@gmail.com>
db29404 to
bafc862
Compare
Add run_testsuite_regressions.sh, which runs every test in
osm-3s_testing/input/regression_*/ and compares its output with
expected/regression_*/, and call it from run_testsuite.sh. Each test is
one directory, so a fix can add its test without changing a script:
stdin.log the query (for a CGI test, the request body, if any)
init.osm optional: data imported into a database of the test's own
import.args optional: arguments for update_database (default --meta)
env optional: run cgi-bin/interpreter with these environment
variables instead of osm3s_query, with a dispatcher over
the test's database
Each test runs for at most 60 seconds and writes at most 10 MB per file,
so a test of a hang fails rather than blocks the suite. The database is
created with mktemp, because the dispatcher's socket path in a directory
under osm-3s_testing/run can exceed the length limit for socket paths.
osm-3s_testing/README.regressions describes how to add a test.
The tests:
- regression_ql_nesting_limit (04c045b, "Stop the OverpassQL parser
looping past the nesting limit"): node(1); inside 1024 levels of
parentheses. The parser reports that nesting is limited to 1023 levels
and stops. Without the fix, it reports parse errors without end.
- regression_user_touched_relations (#7): on one relation, way and two
nodes by uid 1,
rel(1); nwr._(uid_touched:999999999); out count;
rel(1); nwr._(uid_touched:1); out count;
count 0 and 1 relations. Without the fix, the first counts 1 relation.
- regression_cgi_custom_url_line_break (#4): a GET request for
data=[out:custom];node(1);out; with url=http://example.com/%0d%0aX-Injected:%201
is rejected with 400 Bad Request. Without the fix, the response is a
302 redirect with an extra header line "X-Injected: 1".
- regression_cgi_bbox_not_numeric (#4): a GET request for
data=node(bbox);out; with bbox=7,51,8);node(id:1,52 fails to parse.
Without the fix, the value is substituted as is, the query becomes
node(51,7,52,8);node(id:1);out; and returns node 1.
Reverting one fix on this branch makes its tests fail and no others:
git revert -n 04c045b # regression_ql_nesting_limit
git revert -n 4a9c1b5 # regression_user_touched_relations
git revert -n -m 1 8edf11b # the two regression_cgi_* tests
Not covered: the parts of #4 that leave the output of these requests
unchanged (reading the POST body in chunks, a "%" at the end of the
input, the scope of the "=" search, the operates_* checks in
pt_diagrams), the cgi-bin shell scripts of #3, and #8 and #11, which
change only performance.
Co-Authored-By: Colin Dellow <cldellow@gmail.com>
Add run_testsuite_regressions.sh, which runs every test in
osm-3s_testing/input/regression_*/ and compares its output with
expected/regression_*/, and call it from run_testsuite.sh. Each test is
one directory, so a fix can add its test without changing a script:
stdin.log the query (for a CGI test, the request body, if any)
init.osm optional: data imported into a database of the test's own
import.args optional: arguments for update_database (default --meta)
env optional: run cgi-bin/interpreter with these environment
variables instead of osm3s_query, with a dispatcher over
the test's database
Each test runs for at most 60 seconds and writes at most 10 MB per file,
so a test of a hang fails rather than blocks the suite. The database is
created with mktemp, because the dispatcher's socket path in a directory
under osm-3s_testing/run can exceed the length limit for socket paths.
osm-3s_testing/README.regressions describes how to add a test.
The following commits add tests for the fixes since v0.7.62.11. They
leave out the parts of #4 that leave the output of a request unchanged
(reading the POST body in chunks, a "%" at the end of the input, the
scope of the "=" search, the operates_* checks in pt_diagrams), the
cgi-bin shell scripts of #3, and #8 and #11, which change only
performance.
Co-Authored-By: Colin Dellow <cldellow@gmail.com>
Add run_testsuite_regressions.sh, which runs every test in
osm-3s_testing/input/regression_*/ and compares its output with
expected/regression_*/, and call it from run_testsuite.sh. Each test is
one directory, so a fix can add its test without changing a script:
stdin.log the query (for a CGI test, the request body, if any)
init.osm optional: data imported into a database of the test's own
import.args optional: arguments for update_database (default --meta)
env optional: run cgi-bin/interpreter with these environment
variables instead of osm3s_query, with a dispatcher over
the test's database
Each test runs for at most 60 seconds and writes at most 10 MB per file,
so a test of a hang fails rather than blocks the suite. The database is
created with mktemp, because the dispatcher's socket path in a directory
under osm-3s_testing/run can exceed the length limit for socket paths.
osm-3s_testing/README.regressions describes how to add a test.
The following commits add tests for the fixes since v0.7.62.11. They
leave out the parts of #4 that leave the output of a request unchanged
(reading the POST body in chunks, the scope of the "=" search, the
operates_* checks in pt_diagrams), the cgi-bin shell scripts of #3,
and the performance changes of #8 and #11.
Co-Authored-By: Colin Dellow <cldellow@gmail.com>
Add run_testsuite_regressions.sh, which runs every test in
osm-3s_testing/input/regression_*/ and compares its output with
expected/regression_*/, and call it from run_testsuite.sh. Each test is
one directory, so a fix can add its test without changing a script:
stdin.log the query (for a CGI test, the request body, if any)
init.osm optional: data imported into a database of the test's own
import.args optional: arguments for update_database (default --meta)
env optional: run cgi-bin/interpreter with these environment
variables instead of osm3s_query, with a dispatcher over
the test's database
Each test runs for at most 60 seconds and writes at most 10 MB per file,
so a test of a hang fails rather than blocks the suite. The database is
created with mktemp, because the dispatcher's socket path in a directory
under osm-3s_testing/run can exceed the length limit for socket paths.
The script passes shellcheck.
The following commits add tests for the fixes since v0.7.62.11. They
leave out the parts of #4 that leave the output of a request unchanged
(reading the POST body in chunks, the scope of the "=" search, the
operates_* checks in pt_diagrams), the cgi-bin shell scripts of #3,
and the performance changes of #8 and #11.
Co-Authored-By: Colin Dellow <cldellow@gmail.com>
Add run_testsuite_regressions.sh, which runs every test in
osm-3s_testing/input/regression_*/ and compares its output with
expected/regression_*/, and call it from run_testsuite.sh. Each test is
one directory, so a fix can add its test without changing a script:
stdin.log the query (for a CGI test, the request body, if any)
init.osm optional: data imported into a database of the test's own
import.args optional: arguments for update_database (default --meta)
env optional: run cgi-bin/interpreter with these environment
variables instead of osm3s_query, with a dispatcher over
the test's database
Each test runs for at most 60 seconds and writes at most 10 MB per file,
so a test of a hang fails rather than blocks the suite. The database is
created with mktemp, because the dispatcher's socket path in a directory
under osm-3s_testing/run can exceed the length limit for socket paths.
The script passes shellcheck.
The following commits add tests for the fixes since v0.7.62.11. They
leave out the parts of #4 that leave the output of a request unchanged
(reading the POST body in chunks, the scope of the "=" search, the
operates_* checks in pt_diagrams), the cgi-bin shell scripts of #3,
and the performance changes of #8 and #11.
Co-Authored-By: Colin Dellow <cldellow@gmail.com>
Add run_testsuite_regressions.sh, which runs every test in
osm-3s_testing/input/regression_*/ and compares its output with
expected/regression_*/, and call it from run_testsuite.sh. Each test is
one directory, so a fix can add its test without changing a script:
stdin.log the query (for a CGI test, the request body, if any)
init.osm optional: data imported into a database of the test's own
import.args optional: arguments for update_database (default --meta)
env optional: run cgi-bin/interpreter with these environment
variables instead of osm3s_query, with a dispatcher over
the test's database
Each test runs for at most 60 seconds and writes at most 10 MB per file,
so a test of a hang fails rather than blocks the suite. The database is
created with mktemp, because the dispatcher's socket path in a directory
under osm-3s_testing/run can exceed the length limit for socket paths.
The script passes shellcheck.
The following commits add tests for the fixes since v0.7.62.11. They
leave out the parts of #4 that leave the output of a request unchanged
(reading the POST body in chunks, the scope of the "=" search, the
operates_* checks in pt_diagrams), the cgi-bin shell scripts of #3,
and the performance changes of #8 and #11.
Co-Authored-By: Colin Dellow <cldellow@gmail.com>
Fixes #5.
Change
The expensive
aroundfilters (filter_nodes_expensive,filter_ways_expensive,filter_relations_expensiveinstatements/around.cc) ran to completion before any health check. A slowaroundtherefore enforced the query's[timeout:]only late: it kept a CPU busy for the whole computation, then failed with the timeout error at the next check. It never returned a result past its limit; the cost is wasted CPU and server capacity.This adds a small
Periodic_Health_Checkthat callsrman.health_check(query)periodically. The query now stops with the usualQuery timed outerror once its time is up, as other long-running statements already do (e.g.filter_by_tags.h).is_insideon a way geometry takes the check and ticks it for each point and segment it tests, so a single long way (also one in a candidate relation) can't run unchecked. Counting candidates wasn't enough: a few long ways, such as power lines, tested against a large input took seconds each, so a query could overrun its limit without reaching 256 candidates.Two files (
around.cc,around.h), about 60 lines. No change to the database format or the query API. Queries that finish within their limits behave exactly as before.Impact
On the Nova Scotia test database (see #2), with
[timeout:10]:masteraroundfinishes, so it was still running when killed at 120 s. Without a[timeout:](default 180 s) it was still running after 316 s.runtime error: Query timed out in "query" at line 1 after 14 seconds.A query that
aroundcan finish shows the shape of the old behaviour: with[timeout:5],masterruns for the full 23.5 s and then fails withQuery timed out … after 23 seconds; this PR fails the same way after 6.4 s. Same database, warm cache:Second commit. Found by running fuzz queries with
[timeout:2]and flagging any that overran the limit by more than 5 s (bench/deadline_audit.py, see #2). Againstmaster, 4 of 4,000 queries (2,000 plain, 2,000 history withhistory,users,complete) overran it, all inaround. With the first commit only, 3 of those 4 still overran it by 7–12 s. With both commits, all 4 stop within 1 s of the limit (the limit counts whole seconds). Wall time with[timeout:2]:masterA:
B:
C:
D is a fuzz query on the full-history database: a
wr(poly:…)selection over a 400-vertex ring near 46.13,-59.87, followed bycomplete(4)andcomplete(6)loops, one of which runsway(around:0)["height"]. Its vocabulary comes from licensed data, so its full text isn't given here.Cost of the extra checks: none measurable. CPU time, 5 alternating runs per build, plain database, output identical: benchmark q06 100 → 100 ms; query C with
[timeout:600]9.55 → 9.24 s;way(around:250,44.679085,-63.511161)->.s0; way(around.s0:100); out count;25.2 → 24.0 s;rel(45.566265,-62.428420,45.586924,-62.388716)->.s0; node(around.s0:0)["footway"]; out count;2.27 → 2.30 s.health_checkreads the clock and sums cached set sizes.This matters on CPU-bound production servers: a query that will fail anyway holds a core, and its share of the dispatcher's time budget, until
aroundfinishes.Memory
No new allocations: one counter per
aroundfilter call.Testing
master. 2,996 identical, 4 skipped, 0 differences. The fourth skip is a query that now stops itself with a timeout error instead of running on; the fuzzer counts that as a resource limit, not a difference.complete). That covered 10,000 queries across the plain, area and history databases (6,000 / 2,000 / 2,000), with 0 differences. The per-PR fuzz run above predates a fuzzer fix: about 8% of its queries were invalid on both builds, so it rests on roughly 5,500 queries that ran (see Benchmark queries and differential fuzzer #2).Limitations
master,[timeout:2]) found overruns only inaround. Statements the fuzzer rarely generates, or only with small inputs, may still have unchecked loops. On all-changes, only 1 of 2,000 plain queries reached the limit at all, so audits against it say little.aroundchanges. This is based onmaster, separate from around: use fixed-size arrays for 3-D vectors #7 and the spatial index for around against sets of ways or relations is quadratic (no spatial pruning) #3. It touches different functions in the same file, so a small rebase may be needed depending on merge order.https://claude.ai/code/session_01736kJUqyDw9zM3Bkh2W2QT
Generated by Claude Code