This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a commit to branch few-more-clauses-for-quickjs-scanner
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 1820aadc1d17f8f865175b33fdcf6256740c4d9a
Author: Nick Vatamaniuc <[email protected]>
AuthorDate: Fri Aug 2 16:19:05 2024 -0400

    A few more quickjs scanner fixes
    
    Noticed a few more expected error clauses we could handle to reduce log 
noise.
    
    It should handle `{vdu_doc,{error,{throw,{<<"TypeError">>,{Stack..}}}}, 
...}` cases.
    
    Also noticed that the scanner might leave a db opened and not close if it
    throws an exception from a loop, so be more resilient and put it in the 
`after`
    clause of a `try`.
---
 src/couch_quickjs/src/couch_quickjs_scanner_plugin.erl |  4 ++++
 src/couch_scanner/src/couch_scanner_plugin.erl         | 17 ++++++++++-------
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/src/couch_quickjs/src/couch_quickjs_scanner_plugin.erl 
b/src/couch_quickjs/src/couch_quickjs_scanner_plugin.erl
index 08e4514b4..ee8a76bcc 100644
--- a/src/couch_quickjs/src/couch_quickjs_scanner_plugin.erl
+++ b/src/couch_quickjs/src/couch_quickjs_scanner_plugin.erl
@@ -514,8 +514,12 @@ expected_error(_) ->
 
 expected_error({error, {_, compilation_error, _}}, {error, {_, 
compilation_error, _}}) ->
     true;
+expected_error({error, {_, {compilation_error, _}}}, {error, {_, 
{compilation_error, _}}}) ->
+    true;
 expected_error({error, {_, <<"TypeError">>, _}}, {error, {_, <<"TypeError">>, 
_}}) ->
     true;
+expected_error({error, {_, {<<"TypeError">>, _}}}, {error, {_, 
{<<"TypeError">>, _}}}) ->
+    true;
 expected_error(_, _) ->
     false.
 
diff --git a/src/couch_scanner/src/couch_scanner_plugin.erl 
b/src/couch_scanner/src/couch_scanner_plugin.erl
index 34141a241..e8702d161 100644
--- a/src/couch_scanner/src/couch_scanner_plugin.erl
+++ b/src/couch_scanner/src/couch_scanner_plugin.erl
@@ -360,13 +360,16 @@ scan_docs(#st{} = St, #shard{name = ShardDbName}) ->
     St1 = rate_limit(St, shard),
     case couch_db:open_int(ShardDbName, [?ADMIN_CTX]) of
         {ok, Db} ->
-            St2 = St1#st{db = Db},
-            St3 = db_opened_callback(St2),
-            {ok, St4} = couch_db:fold_docs(Db, fun scan_docs_fold/2, St3, []),
-            St5 = db_closing_callback(St4),
-            couch_db:close(Db),
-            erlang:garbage_collect(),
-            St5#st{db = undefined};
+            try
+                St2 = St1#st{db = Db},
+                St3 = db_opened_callback(St2),
+                {ok, St4} = couch_db:fold_docs(Db, fun scan_docs_fold/2, St3, 
[]),
+                St5 = db_closing_callback(St4),
+                erlang:garbage_collect(),
+                St5#st{db = undefined}
+            after
+                couch_db:close(Db)
+            end;
         {not_found, _} ->
             St1
     end.

Reply via email to