[ 
https://issues.apache.org/jira/browse/COUCHDB-1651?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13579479#comment-13579479
 ] 

Christopher Bonhage commented on COUCHDB-1651:
----------------------------------------------

Alright, I've figured out what's going on!

I added some logging to couch_httpd_rewrite:handle_rewrite_req/3:

    MaxRewritesList = couch_config:get("httpd", "rewrite_limit", "100"),
    MaxRewrites = list_to_integer(MaxRewritesList),
    RewriteCount =
        case get(couch_rewrite_count) of
            undefined -> 0;
            Count -> Count
        end,
    ?LOG_INFO("rewrite recursion depth ~B/~B", [RewriteCount, MaxRewrites]),
    case RewriteCount of
        NumRewrites when NumRewrites < MaxRewrites ->
            put(couch_rewrite_count, NumRewrites + 1);
        _ ->
            throw({bad_request, <<"Exceeded rewrite recursion limit">>})
    end,

I noticed the problem immediately: CouchDB is reusing request processes, but 
not clearing the couch_rewrite_count in the process dictionary!

Apache CouchDB has started. Time to relax.
[info] [<0.36.0>] Apache CouchDB has started on http://0.0.0.0:5984/
[info] [<0.36.0>] Apache CouchDB has started on https://0.0.0.0:6984/
[info] [<0.134.0>] rewrite recursion depth 0/100
[info] [<0.134.0>] 127.0.0.1 - - GET /testdb/testapp/apps/testapp.html 200
[info] [<0.134.0>] rewrite recursion depth 1/100
[info] [<0.134.0>] 127.0.0.1 - - GET 
/testdb/testapp/stylesheets/testapp/screen.css 200
[info] [<0.134.0>] rewrite recursion depth 2/100
[info] [<0.134.0>] 127.0.0.1 - - GET 
/testapp/_design/testapp/_list/image_json/images?_=1360958246705 200
[info] [<0.134.0>] rewrite recursion depth 3/100
[info] [<0.134.0>] 127.0.0.1 - - GET 
/testapp/396/images/1.jpg?key=396&file=1.jpg 200
[info] [<0.134.0>] rewrite recursion depth 4/100
[info] [<0.134.0>] 127.0.0.1 - - GET /testdb/testapp/apps/testapp.html 200
[info] [<0.134.0>] rewrite recursion depth 5/100
[info] [<0.134.0>] 127.0.0.1 - - GET 
/testdb/testapp/stylesheets/testapp/screen.css 304
[info] [<0.134.0>] rewrite recursion depth 6/100
[info] [<0.134.0>] 127.0.0.1 - - GET 
/testapp/_design/testapp/_list/image_json/images?_=1360958261344 200
[info] [<0.134.0>] rewrite recursion depth 7/100
[info] [<0.134.0>] 127.0.0.1 - - GET 
/testapp/_design/testapp/_list/value_json/all?startkey=%5B%5D&endkey=%5B%7B%7D%5D
 304
[info] [<0.134.0>] rewrite recursion depth 8/100
[info] [<0.134.0>] 127.0.0.1 - - GET 
/testapp/245/images/1.jpg?key=245&file=1.jpg 200
[info] [<0.134.0>] rewrite recursion depth 9/100
[info] [<0.134.0>] 127.0.0.1 - - GET 
/testapp/389/images/2.jpg?key=389&file=2.jpg 200
[info] [<0.134.0>] rewrite recursion depth 10/100
[info] [<0.134.0>] 127.0.0.1 - - GET 
/testapp/389/images/1.jpg?key=389&file=1.jpg 200

A quick search through the codebase confirms this:

Searching 130 files for "couch_rewrite_count" (case sensitive)

couchdb/src/couchdb/couch_httpd_rewrite.erl:
  123      MaxRewritesList = couch_config:get("httpd", "rewrite_limit", "100"),
  124      MaxRewrites = list_to_integer(MaxRewritesList),
  125:     case get(couch_rewrite_count) of
  126          undefined ->
  127:             put(couch_rewrite_count, 1);
  128          NumRewrites when NumRewrites < MaxRewrites ->
  129:             put(couch_rewrite_count, NumRewrites + 1);
  130          _ ->
  131              throw({bad_request, <<"Exceeded rewrite recursion limit">>})

3 matches in 1 file
                
> Server responds 400 "Exceeded rewrite recursion limit" indefinitely
> -------------------------------------------------------------------
>
>                 Key: COUCHDB-1651
>                 URL: https://issues.apache.org/jira/browse/COUCHDB-1651
>             Project: CouchDB
>          Issue Type: Bug
>          Components: HTTP Interface
>            Reporter: Paul Frazee
>
> Running 1.2.1 on Windows 7 as a service.
> hosts file includes "127.0.0.1 grimwire.local"
> CouchDB conf includes vhosts entries:
> grimwire.local:5984            /grimwire/_design/grimwire/_rewrite
> grimwire.local:5984/local      /grimwire/_design/local/_rewrite
> 'grimwire' design doc rewrites:
> [
>       {
>               "from": "",
>               "to": "index.html",
>               "method": "GET"
>       },
>       {
>               "from": "*",
>               "to": "*"
>       }
> ]
> 'local' design doc rewrites:
> [
>       {
>               "from":"",
>               "to":"index.html",
>               "method":"GET"
>       },
>       {
>               "from":"/posts",
>               "to":"_list/wallpost/wallpost-by-created_at",
>               "method":"GET"
>       },
>       {
>               "from":"/posts",
>               "to":"_update/wallpost",
>               "method":"POST"
>       },
>       {
>               "from":"/posts/:id",
>               "to":"_show/wallpost/:id",
>               "method":"GET"
>       },
>       {
>               "from":"/posts/:id",
>               "to":"_update/wallpost/:id",
>               "method":"PUT"
>       },
>       {
>               "from":"*",
>               "to":"*"
>       }
> ]
> Problem:
> The requests work as expected for some unknown period, then begin to respond 
> with a 400 status and the "Exceeded rewrite recursion limit" error message. 
> Changing the rewrites rules for both applications, including setting them to 
> empty arrays, had no effect.
> The problem was solved by restarting the CouchDB service.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to