Made a script to replicate the issue:

```shell
#!/bin/bash

S=localhost:15984
SA=adm:pass@${S}
JSON="Content-Type: application/json"

curl -s -XDELETE $SA/db > /dev/null
curl -s -XDELETE $SA/srcdb > /dev/null
curl -s -XDELETE $SA/_replicator > /dev/null
curl -s -XPUT $SA/db > /dev/null
curl -s -XPUT $SA/srcdb > /dev/null

echo "Setting [couch_httpd_auth] timeout = 5"
curl -s -XPUT adm:pass@localhost:15986/_config/couch_httpd_auth/timeout -d 
'"5"' > /dev/null
curl -s -XPUT adm:pass@localhost:25986/_config/couch_httpd_auth/timeout -d 
'"5"' > /dev/null
curl -s -XPUT adm:pass@localhost:35986/_config/couch_httpd_auth/timeout -d 
'"5"' > /dev/null

echo "Adding VDU to target"
cat <<EOF > /tmp/vdu.json
  {
    "_id": "_design/vdu",
    "validate_doc_update":"function(newDoc, oldDoc, userCtx) { log(userCtx); if 
(newDoc.name != userCtx.name) { throw({'forbidden': 'VDU failed'}); } }"
  }
EOF
curl -s -XPUT $SA/db/_design/vdu -H "$JSON" -T /tmp/vdu.json > /dev/null

echo "Replicating from srcdb to db"
curl -s XDELETE $SA/_replicate -H "$JSON" -d 
'{"source":"http://adm:pass@localhost:15984/srcdb";, 
"target":"http://adm:pass@localhost:15984/db";, "worker_proceses":1, 
"continuous":true}' > /dev/null
curl -s XPOST   $SA/_replicate -H "$JSON" -d 
'{"source":"http://adm:pass@localhost:15984/srcdb";, 
"target":"http://adm:pass@localhost:15984/db";, "worker_proceses":1, 
"continuous":true}' > /dev/null

sleep 3

DOCID=0

echo "With frequent enough updates, session is getting refreshed"
while [ $DOCID -lt 2 ]; do
    let DOCID++
    echo ""
    echo "DocID: $DOCID"
    curl -s -XPUT $SA/srcdb/$DOCID -H "$JSON" -d '{"name":"adm"}' > /dev/null
    echo "Doc added to source, sleeping 2 seconds"
    sleep 2
    echo "Getting doc from target:"
    curl $SA/db/$DOCID
done

echo "With long sleeps, sesssion will timeout and not get refreshed"
sleep 10

while [ $DOCID -lt 10 ]; do
    let DOCID++
    echo ""
    echo "DocID: $DOCID"
    curl -s -XPUT $SA/srcdb/$DOCID -H "$JSON" -d '{"name":"adm"}' > /dev/null
    echo "Doc added to source, sleeping 7 seconds"
    sleep 7
    echo "Getting doc from target:"
    curl $SA/db/$DOCID
done

```

It can be run against a default dev cluster:

```
$. /replicate_session_with_vdu_auth.sh
Setting [couch_httpd_auth] timeout = 5
Adding VDU to target
Replicating from srcdb to db
With frequent enough updates, session is getting refreshed

DocID: 1
Doc added to source, sleeping 2 seconds
Getting doc from target:
{"_id":"1","_rev":"1-66e95cbbe626e928747ecc225341b2d6","name":"adm"}

DocID: 2
Doc added to source, sleeping 2 seconds
Getting doc from target:
{"_id":"2","_rev":"1-66e95cbbe626e928747ecc225341b2d6","name":"adm"}
With long sleeps, sesssion will timeout and not get refreshed

DocID: 3
Doc added to source, sleeping 7 seconds
Getting doc from target:
{"error":"not_found","reason":"missing"}

DocID: 4
Doc added to source, sleeping 7 seconds
Getting doc from target:
{"error":"not_found","reason":"missing"}
```


[ Full content available at: https://github.com/apache/couchdb/issues/1607 ]
This message was relayed via gitbox.apache.org for [email protected]

Reply via email to