benoitc / couchbeam

Apache CouchDB client in Erlang
Other
242 stars 114 forks source link

couchbeam_view:fetch/3 seems to fail for views that contain no rows. #97

Closed mikebeam closed 10 years ago

mikebeam commented 10 years ago

Hi Benoit,

Using couchbeam 0.9.1, I created a database named "testdb" with the following design document to simulate a view that returns no rows:

{
   "_id": "_design/test",
   "language": "javascript",
   "views": {
       "test": {
           "map": "function(doc) {}"
       }
   }
}

Running this code:

-module(view_test).

-export[t/0].

t() ->
    couchbeam:start(),
    Server = couchbeam:server_connection( "http://localhost:5984", []),
    {ok, DB} = couchbeam:open_or_create_db( Server, "testdb", []),
    {ok, Rows} = couchbeam_view:fetch( DB, {"test", "test"}),
    Rows.

Produces this error:

** exception error: no match of right hand side value
                    {error,{unknown_error,{{error,{case_clause,done},
                                                  [{hackney_stream,stream_loop,4,
                                                                   [{file,"src/hackney_stream.erl"},{line,42}]},
                                                   {hackney_stream,init,4,
                                                                   [{file,"src/hackney_stream.erl"},{line,31}]},
                                                   {proc_lib,init_p_do_apply,3,
                                                             [{file,"proc_lib.erl"},{line,227}]}]},
                                           "An unexpected error occurred."}},
                           []}
     in function  view_test:t/0 (view_test.erl, line 9)

Adding this:

done -> hackney_reponse:stream_body(Client);

to the first case statement of hackney_stream:stream_loop/4 resolves the issue, but I have no idea if that's an appropriate solution, so I didn't bother with a pull request.

Thanks for all of the work you do.

Best, Mike Beam

benoitc commented 10 years ago

I just tested on my machine:

1> couchbeam:start().
ok
2> Server = couchbeam:server_connection( "http://localhost:5984", []).
{server,"http://localhost:5984",[]}
3> {ok, DB} = couchbeam:open_or_create_db(Server, "testdb1", []). 
{ok,{db,{server,"http://localhost:5984",[]},"testdb1",[]}}
4> {ok, Rows} = couchbeam_view:fetch( DB, {"test", "test"}).
{ok,[]}
5> Rows.
[]
6> 

No issue :/ Whcih version of hackney is used? Also which version of couchdb?

benoitc commented 10 years ago

ok even if I didn't reproduced it i figured when it happen. This case can happen when the response is closed but we return some data:

https://github.com/benoitc/hackney/blob/master/src/hackney_response.erl#L288

fixed in hackney in : https://github.com/benoitc/hackney/commit/ad4cc47171d4b0ae1da62508b6ea83a3e762e102

I will make a release tomorrow. Need to add another patch first.

mikebeam commented 10 years ago

Fantastic! Thanks!

On Dec 6, 2013, at 3:11 PM, Benoit Chesneau notifications@github.com wrote:

ok even if I didn't reproduced it i figured when it happen. This case can happen when the response is closed but we return some data:

https://github.com/benoitc/hackney/blob/master/src/hackney_response.erl#L288

fixed in hackney in : benoitc/hackney@ad4cc47

I will make a release tomorrow. Need to add another patch first.

— Reply to this email directly or view it on GitHub.

benoitc commented 10 years ago

fixed 2 days ago. thanks for the feedback :)