Nolan Lawson created COUCHDB-2758:
-------------------------------------
Summary: Deleting non-existant _local doc in _bulk_docs causes 500
Key: COUCHDB-2758
URL: https://issues.apache.org/jira/browse/COUCHDB-2758
Project: CouchDB
Issue Type: Bug
Security Level: public (Regular issues)
Components: Database Core
Reporter: Nolan Lawson
Attachments: couch-2758.sh
Normally you should be able to update/add/delete {{_local}} docs in a
{{_bulk_docs}} request, but if the {{_local}} doc doesn't exist (or if the
provided {{_rev}} is wrong), then the database crashes.
Attached is a bash script using cURL to reproduce. Notice I'm adding two normal
docs ({{mothra}} and {{rodan}}) and then I attempt to delete those two in a
{{_bulk_docs}} along with a nonexistent {{_local}} doc called
{{_local/godzilla}}. (Sorry for the goofy theme; I've been getting tired of foo
and bar.)
I expect to get back an array of results describing the 2 docs that succeeded
as well as the 1 doc that failed. Instead I get a crash:
{code}
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,237}]}]}}
** When Server state == {db,<0.3217.15>,<0.3218.15>,nil,
<<"1438060201861904">>,<0.3216.15>,<0.3136.15>,
<0.3220.15>,
{db_header,6,0,0,nil,nil,nil,0,nil,nil,1000},
0,
{btree,<0.3136.15>,
{316,{2,0,78},116},
#Fun<couch_db_updater.10.11117096>,
#Fun<couch_db_updater.11.11117096>,
#Fun<couch_btree.5.131744168>,
#Fun<couch_db_updater.12.11117096>,snappy},
{btree,<0.3136.15>,
{432,2,103},
#Fun<couch_db_updater.13.11117096>,
#Fun<couch_db_updater.14.11117096>,
#Fun<couch_btree.5.131744168>,
#Fun<couch_db_updater.15.11117096>,snappy},
{btree,<0.3136.15>,nil,
#Fun<couch_btree.3.131744168>,
#Fun<couch_btree.4.131744168>,
#Fun<couch_btree.5.131744168>,nil,snappy},
2,<<"testdb">>,
"/usr/local/var/lib/couchdb/testdb.couch",[],[],
nil,
{user_ctx,null,[],undefined},
#Ref<0.0.16.194130>,1000,
[before_header,after_header,on_file_open],
[create,
{user_ctx,
{user_ctx,null,
[<<"_admin">>],
<<"{couch_httpd_auth,
default_authentication_handler}">>}}],
snappy,nil,nil}
** Reason for termination ==
** {function_clause,
[{couch_db_updater,'-update_local_docs/2-fun-0-',
[{<0.3111.15>,
{{doc,<<"_local/godzilla">>,{1,[<<"fake">>]},{[]},[],true,[]},
#Ref<0.0.16.194164>}},
not_found],
[{file,"couch_db_updater.erl"},{line,730}]},
{lists,zipwith,3,[{file,"lists.erl"},{line,449}]},
{couch_db_updater,update_local_docs,2,
[{file,"couch_db_updater.erl"},{line,729}]},
{couch_db_updater,update_docs_int,5,
[{file,"couch_db_updater.erl"},{line,695}]},
{couch_db_updater,handle_info,2,
[{file,"couch_db_updater.erl"},{line,235}]},
{gen_server,try_dispatch,4,[{file,"gen_server.erl"},{line,593}]},
{gen_server,handle_msg,5,[{file,"gen_server.erl"},{line,659}]},
{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,237}]}]}
[Tue, 28 Jul 2015 05:10:01 GMT] [error] [<0.3217.15>] {error_report,<0.30.0>,
{<0.3217.15>,crash_report,
[[{initial_call,{couch_db,init,['Argument__1']}},
{pid,<0.3217.15>},
{registered_name,[]},
{error_info,
{exit,
{function_clause,
[{couch_db_updater,
'-update_local_docs/2-fun-0-',
[{<0.3111.15>,
{{doc,<<"_local/godzilla">>,
{1,[<<"fake">>]},
{[]},
[],true,[]},
#Ref<0.0.16.194164>}},
not_found],
[{file,"couch_db_updater.erl"},{line,730}]},
{lists,zipwith,3,
[{file,"lists.erl"},{line,449}]},
{couch_db_updater,update_local_docs,2,
[{file,"couch_db_updater.erl"},{line,729}]},
{couch_db_updater,update_docs_int,5,
[{file,"couch_db_updater.erl"},{line,695}]},
{couch_db_updater,handle_info,2,
[{file,"couch_db_updater.erl"},{line,235}]},
{gen_server,try_dispatch,4,
[{file,"gen_server.erl"},{line,593}]},
{gen_server,handle_msg,5,
[{file,"gen_server.erl"},{line,659}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,237}]}]},
[{gen_server,terminate,7,
[{file,"gen_server.erl"},{line,804}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,237}]}]}},
{ancestors,[<0.3214.15>]},
{messages,[]},
{links,[<0.84.0>]},
{dictionary,[]},
{trap_exit,true},
{status,running},
{heap_size,1598},
{stack_size,27},
{reductions,403}],
[]]}}
[Tue, 28 Jul 2015 05:10:01 GMT] [error] [<0.3111.15>] Uncaught error in HTTP
request: {exit,
{function_clause,
[{couch_db_updater,
'-update_local_docs/2-fun-0-',
[{<0.3111.15>,
{{doc,
<<"_local/godzilla">>,
{1,[<<"fake">>]},
{[]},
[],true,[]},
#Ref<0.0.16.194164>}},
not_found],
[{file,
"couch_db_updater.erl"},
{line,730}]},
{lists,zipwith,3,
[{file,"lists.erl"},
{line,449}]},
{couch_db_updater,
update_local_docs,2,
[{file,
"couch_db_updater.erl"},
{line,729}]},
{couch_db_updater,
update_docs_int,5,
[{file,
"couch_db_updater.erl"},
{line,695}]},
{couch_db_updater,
handle_info,2,
[{file,
"couch_db_updater.erl"},
{line,235}]},
{gen_server,
try_dispatch,4,
[{file,
"gen_server.erl"},
{line,593}]},
{gen_server,
handle_msg,5,
[{file,
"gen_server.erl"},
{line,659}]},
{proc_lib,
init_p_do_apply,3,
[{file,
"proc_lib.erl"},
{line,237}]}]}}
[Tue, 28 Jul 2015 05:10:01 GMT] [error] [<0.84.0>] Unexpected exit of database
process <0.3217.15> [<<"testdb">>]: {function_clause,
[{couch_db_updater,
'-update_local_docs/2-fun-0-',
[{<0.3111.15>,
{{doc,
<<"_local/godzilla">>,
{1,
[<<"fake">>]},
{[]},
[],
true,
[]},
#Ref<0.0.16.194164>}},
not_found],
[{file,
"couch_db_updater.erl"},
{line,
730}]},
{lists,
zipwith,
3,
[{file,
"lists.erl"},
{line,
449}]},
{couch_db_updater,
update_local_docs,
2,
[{file,
"couch_db_updater.erl"},
{line,
729}]},
{couch_db_updater,
update_docs_int,
5,
[{file,
"couch_db_updater.erl"},
{line,
695}]},
{couch_db_updater,
handle_info,
2,
[{file,
"couch_db_updater.erl"},
{line,
235}]},
{gen_server,
try_dispatch,
4,
[{file,
"gen_server.erl"},
{line,
593}]},
{gen_server,
handle_msg,
5,
[{file,
"gen_server.erl"},
{line,
659}]},
{proc_lib,
init_p_do_apply,
3,
[{file,
"proc_lib.erl"},
{line,
237}]}]}
[Tue, 28 Jul 2015 05:10:01 GMT] [info] [<0.3111.15>] Stacktrace:
[{couch_db,collect_results,3,
[{file,"couch_db.erl"},{line,833}]},
{couch_db,write_and_commit,4,
[{file,"couch_db.erl"},{line,845}]},
{couch_db,update_docs,4,
[{file,"couch_db.erl"},{line,782}]},
{couch_httpd_db,db_req,2,
[{file,"couch_httpd_db.erl"},
{line,330}]},
{couch_httpd_db,do_db_req,2,
[{file,"couch_httpd_db.erl"},
{line,234}]},
{couch_httpd,handle_request_int,5,
[{file,"couch_httpd.erl"},{line,318}]},
{mochiweb_http,headers,5,
[{file,"mochiweb_http.erl"},{line,94}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,237}]}]
[Tue, 28 Jul 2015 05:10:01 GMT] [error] [<0.3111.15>] {error_report,<0.30.0>,
{<0.3111.15>,crash_report,
[[{initial_call,
{mochiweb_acceptor,init,
['Argument__1','Argument__2','Argument__3']}},
{pid,<0.3111.15>},
{registered_name,[]},
{error_info,
{error,badarg,
[{erlang,list_to_binary,
[[{couch_db_updater,
'-update_local_docs/2-fun-0-',
[{<0.3111.15>,
{{doc,<<"_local/godzilla">>,
{1,[<<"fake">>]},
{[]},
[],true,[]},
#Ref<0.0.16.194164>}},
not_found],
[{file,"couch_db_updater.erl"},{line,730}]},
{lists,zipwith,3,
[{file,"lists.erl"},{line,449}]},
{couch_db_updater,update_local_docs,2,
[{file,"couch_db_updater.erl"},{line,729}]},
{couch_db_updater,update_docs_int,5,
[{file,"couch_db_updater.erl"},{line,695}]},
{couch_db_updater,handle_info,2,
[{file,"couch_db_updater.erl"},{line,235}]},
{gen_server,try_dispatch,4,
[{file,"gen_server.erl"},{line,593}]},
{gen_server,handle_msg,5,
[{file,"gen_server.erl"},{line,659}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,237}]}]],
[]},
{couch_httpd,error_info,1,
[{file,"couch_httpd.erl"},{line,818}]},
{couch_httpd,send_error,2,
[{file,"couch_httpd.erl"},{line,925}]},
{couch_httpd,handle_request_int,5,
[{file,"couch_httpd.erl"},{line,368}]},
{mochiweb_http,headers,5,
[{file,"mochiweb_http.erl"},{line,94}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,237}]}]}},
{ancestors,
[couch_httpd,couch_secondary_services,
couch_server_sup,<0.31.0>]},
{messages,[]},
{links,[<0.101.0>,#Port<0.320113>]},
{dictionary,
[{mochiweb_request_body,
<<"{\"new_edits\":true,\"docs\":[{\"_id\":\"mothra\",\"_rev\":\"1-967a00dff5e02add41819138abb3284d\",\"_deleted\":true},{\"_id\":\"_local/godzilla\",\"_rev\":\"1-fake\",\"_deleted\":true},{\"_id\":\"rodan\",\"_rev\":\"1-967a00dff5e02add41819138abb3284d\",\"_deleted\":true}]}">>},
{couch_rewrite_count,0},
{mochiweb_request_recv,true},
{mochiweb_request_cookie,[]}]},
{trap_exit,false},
{status,running},
{heap_size,4185},
{stack_size,27},
{reductions,11631}],
[]]}}
[Tue, 28 Jul 2015 05:10:38 GMT] [info] [<0.3198.15>] 127.0.0.1 - - DELETE
/testdb/ 200
[Tue, 28 Jul 2015 05:10:38 GMT] [info] [<0.3047.15>] 127.0.0.1 - - PUT /testdb/
201
[Tue, 28 Jul 2015 05:10:38 GMT] [info] [<0.3049.15>] 127.0.0.1 - - PUT
/testdb/mothra 201
[Tue, 28 Jul 2015 05:10:38 GMT] [info] [<0.3221.15>] 127.0.0.1 - - PUT
/testdb/rodan 201
[Tue, 28 Jul 2015 05:10:38 GMT] [info] [<0.3227.15>] 127.0.0.1 - - POST
/testdb/_bulk_docs?_nonce=1438060065251 201
{code}
Related to [PouchDB issue 4086](https://github.com/pouchdb/pouchdb/issues/4086).
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
