Repository: tinode/chat

Issue #738: hub: missing both subscriptions for 'p2pxEtcnfc1MVZ3RBB_Vu_lgQ' (SHOULD NEVER HAPPEN!)
Created: 2022-03-30T09:28:29Z
tinode version: master
To reproduce:

2 users that haven't talked to each other before
user A attaches to user B (2 p2p subs are created)
user A deletes his subscription to user B
user B deletes his subscription to user A
user B tries to sub to user A

expected: user B subs successfully
got: tinode        | 2022/03/30 08:31:45 hub: missing both subscriptions for 'p2pxEtcnfc1MVZ3RBB_Vu_lgQ' (SHOULD NEVER HAPPEN!) tinode        | 2022/03/30 08:31:45 init_topic: failed to load or create topic: p2pxEtcnfc1MVZ3RBB_Vu_lgQ internal 
user A logs:
tinode        | 2022/03/30 08:45:54 in: '{"hi":{"id":"88142","ver":"0.18.3","ua":"tinodejs/0.18.3","lang":"en-US","platf":"web"}}' sid='zpVjNxkZhlc' uid=''
tinode        | 2022/03/30 08:44:03 in: '{"login":{"id":"88132","scheme":"sch","secret":"secr<...>' sid='zpVjNxkZhlc' uid=''
tinode        | 2022/03/30 08:44:08 in: '{"sub":{"id":"88133","topic":"me","get":{"what":"sub desc tags cred"}}}' sid='zpVjNxkZhlc' uid='RSpSx6akRu4'
tinode        | 2022/03/30 08:44:11 in: '{"sub":{"id":"88138","topic":"usrmaZcF8p7Z4Y","get":{"data":{"limit":24},"what":"data sub desc"}}}' sid='zpVjNxkZhlc' uid='RSpSx6akRu4'
tinode        | 2022/03/30 08:44:14 in: '{"del":{"id":"88140","topic":"usrmaZcF8p7Z4Y","what":"topic"}}' sid='zpVjNxkZhlc' uid='RSpSx6akRu4'

user B logs:
tinode        | 2022/03/30 08:45:54 in: '{"hi":{"id":"88142","ver":"0.18.3","ua":"tinodejs/0.18.3","lang":"en-US","platf":"web"}}' sid='EF28c-EArwA' uid=''
tinode        | 2022/03/30 08:45:54 in: '{"login":{"id":"88143","scheme":"sch","secret":"secr' sid='EF28c-EArwA' uid=''
tinode        | 2022/03/30 08:45:59 in: '{"sub":{"id":"88144","topic":"me","get":{"what":"sub desc tags cred"}}}' sid='EF28c-EArwA' uid='maZcF8p7Z4Y'
tinode        | 2022/03/30 08:46:02 in: '{"sub":{"id":"88145","topic":"usrRSpSx6akRu4","get":{"data":{"limit":24},"desc":{"ims":"2022-03-30T08:44:11.928Z"},"what":"data sub desc"}}}' sid='EF28c-EArwA' uid='maZcF8p7Z4Y'
tinode        | 2022/03/30 08:46:07 in: '{"del":{"id":"88147","topic":"usrRSpSx6akRu4","what":"topic"}}' sid='EF28c-EArwA' uid='maZcF8p7Z4Y'
tinode        | 2022/03/30 08:46:11 in: '{"sub":{"id":"88153","topic":"usrRSpSx6akRu4","get":{"data":{"limit":24},"desc":{"ims":"2022-03-30T08:42:42.610Z"},"what":"data sub desc"}}}' sid='EF28c-EArwA' uid='maZcF8p7Z4Y'
tinode        | 2022/03/30 08:46:11 hub: missing both subscriptions for 'p2pmaZcF8p7Z4ZFKlLHpqRG7g' (SHOULD NEVER HAPPEN!)
tinode        | 2022/03/30 08:46:11 init_topic: failed to load or create topic: p2pmaZcF8p7Z4ZFKlLHpqRG7g internal

The same problem appears if instead of {del}, {leave} unsub=true packets are used.

Duplicate issue #747: P2P conversations cannot be restored after {leave unsub=true}
Created: 2022-05-04T08:44:44Z
tinode version: 0.18.5
After this fix P2P conversations cannot be restored after both users {leave unsub=true}.
To reproduce, start with a fresh install of sandbox tinode and run reproduce.html in browser.
reproduce.html:
<!DOCTYPE html>
<html lang="en">
<head>
    <script crossorigin="anonymous"
      src="https://cdn.jsdelivr.net/npm/tinode-sdk/umd/tinode.dev.js">
    </script>
    <meta charset="UTF-8">
</head>

<body id="home">
	<h1>HTML5 boilerplate</h1>
<script>
u1 = {
    u: "alice",
    p: "alice123",
}
u2 = {
    u: "bob",
    p: "bob123",
}

t1 = new Tinode({
    host: "localhost:6060",
    apiKey: "AQEAAAABAAD_rAp4DJh05a1HAwFT3A6K",
});
t2 = new Tinode({
    host: "localhost:6060",
    apiKey: "AQEAAAABAAD_rAp4DJh05a1HAwFT3A6K",
});

async function run() {
    await t1.connect()
    await t1.loginBasic(u1.u, u1.p)
    await t2.connect()
    await t2.loginBasic(u2.u, u2.p)
    await t1.subscribe(t2.getCurrentUserID())
    await t2.subscribe(t1.getCurrentUserID())
    await t1.leave(t2.getCurrentUserID(), true)
    await t2.leave(t1.getCurrentUserID(), true)
    await t1.subscribe(t2.getCurrentUserID())
}
run()
</script>
</body>
</html>
expected: last subscribe in reproduce.html runs successfully and conversation is restored with previous messages.
got: last subscribe gives {"ctrl":{"id":"118029","topic":"usrrLRncQTBnDg","code":503,"text":"locked","ts":"2022-05-04T08:29:31.127Z"}}
user1 logs:
{"hi":{"id":"118025","ver":"0.18.3","ua":"Undefined (Firefox/95.0; Linux x86_64); tinodejs/0.18.3","lang":"en-US","platf":"web"}}
{"ctrl":{"id":"118025","params":{"build":"mysql:undef","maxFileUploadSize":8388608,"maxMessageSize":262144,"maxSubscriberCount":128,"maxTagCount":16,"maxTagLength":96,"minTagLength":2,"ver":"0.18"},"code":201,"text":"created","ts":"2022-05-04T08:29:31.052Z"}}
{"login":{"id":"118026","scheme":"basic","secret":"Ym9iOmJvYjEyMw=="}}
{"ctrl":{"id":"118026","params":{"authlvl":"auth","expires":"2022-05-18T08:29:31.115Z","token":"Nm9/cppnzEdrroRiFAABAAEAEbHENPtU3yQehINU184fvDKNDiC/oxc26TEFDfgcMwg=","user":"usrNm9_cppnzEc"},"code":200,"text":"ok","ts":"2022-05-04T08:29:31.052Z"}}
{"sub":{"id":"118027","topic":"usrrLRncQTBnDg"}}
{"ctrl":{"id":"118027","topic":"usrrLRncQTBnDg","code":200,"text":"ok","ts":"2022-05-04T08:29:31.118Z"}}
{"pres":{"topic":"usrrLRncQTBnDg","src":"usrrLRncQTBnDg","what":"acs","dacs":{"want":"N","given":"N"}}}
{"leave":{"id":"118028","topic":"usrrLRncQTBnDg","unsub":true}}
{"ctrl":{"id":"118028","topic":"usrrLRncQTBnDg","code":200,"text":"ok","ts":"2022-05-04T08:29:31.125Z"}}
{"sub":{"id":"118029","topic":"usrrLRncQTBnDg"}}
{"ctrl":{"id":"118029","topic":"usrrLRncQTBnDg","code":503,"text":"locked","ts":"2022-05-04T08:29:31.127Z"}}

user2 logs:
{"hi":{"id":"100326","ver":"0.18.3","ua":"Undefined (Firefox/95.0; Linux x86_64); tinodejs/0.18.3","lang":"en-US","platf":"web"}}
{"ctrl":{"id":"100326","params":{"build":"mysql:undef","maxFileUploadSize":8388608,"maxMessageSize":262144,"maxSubscriberCount":128,"maxTagCount":16,"maxTagLength":96,"minTagLength":2,"ver":"0.18"},"code":201,"text":"created","ts":"2022-05-04T08:29:30.97Z"}}
{"login":{"id":"100327","scheme":"basic","secret":"YWxpY2U6YWxpY2UxMjM="}}
{"ctrl":{"id":"100327","params":{"authlvl":"auth","expires":"2022-05-18T08:29:31.036Z","token":"rLRncQTBnDhrroRiFAABAAEAASnT97a1Ei09YNhVPDgRIa26GZ6HetOlq7RVxE17MUg=","user":"usrrLRncQTBnDg"},"code":200,"text":"ok","ts":"2022-05-04T08:29:30.971Z"}}
{"sub":{"id":"100328","topic":"usrNm9_cppnzEc"}}
{"ctrl":{"id":"100328","topic":"usrNm9_cppnzEc","code":200,"text":"ok","ts":"2022-05-04T08:29:31.117Z"}}
{"leave":{"id":"100329","topic":"usrNm9_cppnzEc","unsub":true}}
{"ctrl":{"id":"100329","topic":"usrNm9_cppnzEc","code":200,"text":"ok","ts":"2022-05-04T08:29:31.119Z"}}

Closing comment (2022-05-09T22:28:33Z): Duplicate of #738