Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 25283200CAE for ; Wed, 21 Jun 2017 19:07:42 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 23567160BD0; Wed, 21 Jun 2017 17:07:42 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 4324A160BD5 for ; Wed, 21 Jun 2017 19:07:41 +0200 (CEST) Received: (qmail 46851 invoked by uid 500); 21 Jun 2017 17:07:40 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 46791 invoked by uid 99); 21 Jun 2017 17:07:40 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 21 Jun 2017 17:07:40 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id B0F30CEFC7 for ; Wed, 21 Jun 2017 17:07:39 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1 X-Spam-Level: * X-Spam-Status: No, score=1 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HTML_MESSAGE=2, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1] autolearn=disabled Authentication-Results: spamd1-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=calftrail-com.20150623.gappssmtp.com Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id E_xbaV_L6wpn for ; Wed, 21 Jun 2017 17:07:37 +0000 (UTC) Received: from mail-io0-f178.google.com (mail-io0-f178.google.com [209.85.223.178]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTPS id 2720C5F341 for ; Wed, 21 Jun 2017 17:07:37 +0000 (UTC) Received: by mail-io0-f178.google.com with SMTP id k93so7626683ioi.2 for ; Wed, 21 Jun 2017 10:07:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=calftrail-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:mime-version:subject:date:references:to:in-reply-to; bh=NrWl74oa9ocxlXe8UDM0Aj/gaBr6kB0kGxKIeawd85Q=; b=TI18sQw499ez29i+KEwwrzb943jDePFlpBQlMmudgvyDjBi+TpNrREXCMGDd4mrZW+ uUhp5A+rAuGOLs9drZjot1D2JwZKAMQXSWjkqPvuPLhNxNHeUQJXywRjJ9reFp440leQ DFlKyplkTAxtU8WneBjOEVg5Uj8mruZO8j5TAga6MSrh7Nm8CBkBbiFzrpKh/eBgT8N6 ry32n8y+81BZKUGtIf22EUV4JgTD8A9Nc8SvverrrRquem0S4llp//UDuo6WfZIwLTum Vc9itBz2kzlWvrzh11oIILu1MGxbJ703sSP0NL+ICuNV36SNAXqMgIBNCnjI3jj6gbiu tcUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :references:to:in-reply-to; bh=NrWl74oa9ocxlXe8UDM0Aj/gaBr6kB0kGxKIeawd85Q=; b=YwXX9MDnm96RWoqhOszixy88DdgOPICmwjlQEMbFIm/+y+oTmLZPUQHphweSkEUsz7 6xXTeexK8O/i25G+vLUZQVXwO2TOahuT3YHw4h45wcbRhD6q8SQBQLnGlM9UkLs2bZq9 ePk/281sZsiIydJScrSk/hls2BT5Ewmq+HCOmcO8pVWvr7o9QB03KVRY6GSNoxN/8+IL ayvFBkgu/EawP5Xi/K5FYILQ4MX8hnfa6kzbladT24d7BtQoBqzA/4/ckS5s2BqK+iz0 WlzlwS2zZ0/7qrFsuKvJOV/5lKtBZQoAmlyYZkADkpioUAuKp2HugkO+1gHBNY3sGzT+ DZmw== X-Gm-Message-State: AKS2vOwuuK6WhHBwkDHsuPq1MFp9ZXQCYKZqBM8yzJEKQEUp2+w741YZ ISyqnqLBlRUdB49iSGk= X-Received: by 10.107.11.160 with SMTP id 32mr34482207iol.222.1498064856397; Wed, 21 Jun 2017 10:07:36 -0700 (PDT) Received: from [10.0.0.67] ([97.94.22.63]) by smtp.gmail.com with ESMTPSA id f93sm1540068iod.7.2017.06.21.10.07.34 for (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 21 Jun 2017 10:07:35 -0700 (PDT) From: Nathan Vander Wilt Content-Type: multipart/alternative; boundary="Apple-Mail=_B922C761-A2A0-4074-8CA3-024932A4D2D7" Message-Id: <466BE6B6-8748-4F02-ABEA-414D1E24D0EA@calftrail.com> Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) Subject: Re: Extra 500 reply added to list function response when accessed through rewrite Date: Wed, 21 Jun 2017 10:07:36 -0700 References: <4F709517-AFCF-44A2-9290-FF7C4928FDD0@calftrail.com> <1830441581.2326.1498010152432.JavaMail.Joan@RITA> To: user@couchdb.apache.org In-Reply-To: <1830441581.2326.1498010152432.JavaMail.Joan@RITA> X-Mailer: Apple Mail (2.1878.6) archived-at: Wed, 21 Jun 2017 17:07:42 -0000 --Apple-Mail=_B922C761-A2A0-4074-8CA3-024932A4D2D7 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Thanks, filed as https://github.com/apache/couchdb/issues/607. -nvw On Jun 20, 2017, at 6:55 PM, Joan Touzet wrote: > Hi Nate, >=20 > We've moved to GitHub Issues. A 500 with a stack trace is definitely = evidence of a bug, > we shouldn't ever return a 500 -- though I admit this is a bit of a = corner case. >=20 > https://github.com/apache/couchdb/issues >=20 > I'm not able to dig in on your specific bug right now, but perhaps = someone else can > shed some light? >=20 > Thanks, > Joan >=20 > ----- Original Message ----- > From: "Nathan Vander Wilt" > To: user@couchdb.apache.org > Sent: Tuesday, 20 June, 2017 7:04:05 PM > Subject: Extra 500 reply added to list function response when accessed = through rewrite >=20 > I am getting strange responses from CouchDB 2.0.0 when accessing a = list handler through a rewrite. The result to my single request is two = responses: the expected one, plus an extra "unknown_error" 500 response. = Over HTTP/1.1 this issue is masked because the extra response is not = properly chunked, but over HTTP/1.0 the two responses appear as a single = body before the connection is closed. So in local development the = problem isn't seen in the browser, but when hosted behind an HTTP/1.0 = proxy like nginx in production all clients will see the extra content = appended to the intended HTML. >=20 > Regardless of the HTTP version of the request, the behavior is = accompanied in the console logs by: >=20 > [error] 2017-06-20T20:54:43.637726Z couchdb@localhost <0.23057.8> = 4d6c7d7e8f req_err(2053811356) unknown_error : undef > [<<"lacc:get/2">>,<<"chttpd:split_response/1 = L343">>,<<"chttpd:handle_request_int/1 = L234">>,<<"chttpd:process_request/1 = L293">>,<<"chttpd:handle_request_int/1 = L229">>,<<"mochiweb_http:headers/6 L122">>,<<"proc_lib:init_p_do_apply/3 = L247">>] > [notice] 2017-06-20T20:54:43.637979Z couchdb@localhost <0.23057.8> = 4d6c7d7e8f undefined 127.0.0.1 undefined GET = /test/_design/glob/_rewrite/2015/04/f1040_spreadsheet 500 ok 22 >=20 >=20 > Note there is no separate log for the initial "200" response, just the = second "500" one. >=20 > Turns out if I call `getRows()` an extra times in the list function = (or if there are no matching rows), the extra 500 response does not = happen. Also if I bypass the rewrite and query the list function = directly, I do not see an extra response. >=20 > So it seems there might be a bug, maybe something like "the rewrite = handler generates an extra, broken response if a list function doesn't = consume beyond all the available rows". >=20 > Is this something I should file in JIRA, or have I made a mistake = somewhere? Details below. (The original code can be seen at = https://github.com/natevw/glob but I've simplified things down in my = notes above and still seeing the issue.) >=20 > thanks, > -natevw >=20 >=20 > --- >=20 >=20 > The rewrite used looks like >=20 > "rewrites": [{ > "from": "/:path1/:path2/:path3", > "to": "_list/posts/by_path", > "query": { > "include_docs": "true", > "key": [":path1",":path2",":path3"] > } > }] >=20 > And the list function can be as simple as >=20 > function() { > return "[LIST FN OUTPUT]"; > } >=20 > When I query this such that "key" ends up matching a row from a simple = "by_path" view, I get an extra garbage response when I access the = rewrite: >=20 > $ telnet localhost 5984 > GET /test/_design/glob/_rewrite/2015/04/f1040_spreadsheet >=20 > HTTP/1.1 200 OK > Connection: close > Content-Type: application/json > Date: Tue, 20 Jun 2017 20:34:49 GMT > Server: CouchDB/2.0.0 (Erlang OTP/19) >=20 > [LIST FN OUTPUT]HTTP/1.1 500 Internal Server Error > Cache-Control: must-revalidate > Connection: close > Content-Length: 60 > Content-Type: application/json > Date: Tue, 20 Jun 2017 20:34:49 GMT > Server: CouchDB/2.0.0 (Erlang OTP/19) > X-Couch-Request-ID: 5e0e7f467b > X-Couch-Stack-Hash: 2053811356 > X-CouchDB-Body-Time: 0 >=20 > {"error":"unknown_error","reason":"undef","ref":2053811356} > Connection closed by foreign host. >=20 >=20 > This does not happen with a direct request to the list, bypassing the = rewrite: >=20 > GET = /test/_design/glob/_list/posts/by_path?include_docs=3Dtrue&key=3D["2015","= 04","f1040_spreadsheet"] >=20 > HTTP/1.1 200 OK > Connection: close > Content-Type: application/json > Date: Tue, 20 Jun 2017 20:38:08 GMT > Server: CouchDB/2.0.0 (Erlang OTP/19) >=20 > [LIST FN OUTPUT]Connection closed by foreign host. >=20 >=20 > Nor does it happen if I make a request through the rewrite targeting a = "missing key", i.e. one that was not emitted by the view: >=20 > GET /test/_design/glob/_rewrite/2020/13/not_exist >=20 > HTTP/1.1 200 OK > Connection: close > Content-Type: application/json > Date: Tue, 20 Jun 2017 20:40:29 GMT > Server: CouchDB/2.0.0 (Erlang OTP/19) >=20 > [LIST FN OUTPUT]Connection closed by foreign host. >=20 >=20 > If I change my list function to >=20 > function() { > getRow(); > getRow(); > return "[LIST FN OUTPUT]"; > } >=20 > then the problem goes away even when accessed via the rewrite. With = just a single call to `getRow()` the extra response persists. >=20 >=20 > Also note that the chunked responses of HTTP/1.1 mask this "double = response" issue, so you'll see it in telnet or if CouchDB is behind = nginx, but not in a browser or similar:=20 >=20 >=20 > GET /test/_design/glob/_rewrite/2015/04/f1040_spreadsheet HTTP/1.1 >=20 > HTTP/1.1 200 OK > Content-Type: application/json > Date: Tue, 20 Jun 2017 20:50:12 GMT > Server: CouchDB/2.0.0 (Erlang OTP/19) > Transfer-Encoding: chunked >=20 > d > [LIST FN OUTPUT] > 0 >=20 > HTTP/1.1 500 Internal Server Error > Cache-Control: must-revalidate > Content-Length: 60 > Content-Type: application/json > Date: Tue, 20 Jun 2017 20:50:12 GMT > Server: CouchDB/2.0.0 (Erlang OTP/19) > X-Couch-Request-ID: 524b67d8db > X-Couch-Stack-Hash: 2053811356 > X-CouchDB-Body-Time: 0 >=20 > {"error":"unknown_error","reason":"undef","ref":2053811356} >=20 --Apple-Mail=_B922C761-A2A0-4074-8CA3-024932A4D2D7--