Rewritten PUT of attachment hangs
- Dominant language
- Erlang
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 9
Description
### Expected Behavior
Using a simple rewrite javascript function that maps to the non-rewrite path should allow uploading attachments.
### Current Behavior
Using PUT to upload attachments hangs and eventually returns {"error":"unknown_error","reason":"undefined"}.
This appears to be very similar to issue #1612. @ermouth, in case you know about this.
### Steps to Reproduce
This creates a database `r` and a design doc `n` that has a rewrite function that should pass the requests to the `r` database unmodified. Using the rewrite function to GET or PUT documents works fine. Using it to PUT an attachment causes the connection to hang for a while and then return an 'unknown_error'.
```
~$ curl http://127.0.0.1:5984
{"couchdb":"Welcome","version":"2.3.0","git_sha":"07ea0c7","uuid":"e07d95a0b0610b7bcb8e046fff5dd1b6","features":["pluggable-storage-engines","scheduler"],"vendor":{"name":"The Apache Software Foundation"}}
~$ curl -X PUT 'http://127.0.0.1:5984/r'
{"ok":true}
~$ curl -X PUT 'http://127.0.0.1:5984/r/_design/n' -d $'{"rewrites": "function (r) { return { path:\'../../\' + r.path.slice(4).join(\'/\') } } "}'
{"ok":true,"id":"_design/n","rev":"1-c19e01e83ea13c586401fa1fa66c6997"}
~$ curl -X PUT http://127.0.0.1:5984/r/_design/n/_rewrite/foo -d '{ }'
{"ok":true,"id":"foo","rev":"1-967a00dff5e02add41819138abb3284d"}
~$ curl -X PUT 'http://127.0.0.1:5984/r/_design/n/_rewrite/foo/test.jpg?rev=1-967a00dff5e02add41819138abb3284d' --data-binary @test.jpg -H "Content-Type: image/jpg"
HANG!!!!
{"error":"unknown_error","reason":"undefined"}
~$ curl -X PUT 'http://127.0.0.1:5984/r/foo/test.jpg?rev=1-967a00dff5e02add41819138abb3284d' --data-binary @test.jpg -H "Content-Type: image/jpg"
{"ok":true,"id":"foo","rev":"2-13c13abad5b38cf5d5a321a00ebf8b77"}
```
Contributor guide
Research direction
Start by reproducing the rewritten attachment PUT against the /_rewrite endpoint, then compare it with the direct database attachment PUT shown in the issue. Trace the rewrite request path and attachment upload handling; done means the rewritten PUT completes successfully and returns the expected document revision instead of hanging or returning unknown_error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- erlang, javascript
- Domain
- api, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100