sagemathinc / cocalc

CoCalc: Collaborative Calculation in the Cloud
https://CoCalc.com
Other
1.17k stars 216 forks source link

invite email sent twice #4345

Closed haraldschilly closed 1 week ago

haraldschilly commented 4 years ago

when I send an email invite (e.g. to a course) to myself, I receive it twice. I suspect this happens for other email types as well. This must be a config problem, bug, or maybe we have to update the node library, I don't know.

haraldschilly commented 4 years ago

After merging this PR above, I tested this for a new course file. I got two emails, despite only one invitation. What's weird: there are two hub-user-api hubs and both of them are sending? Or am I reading this wrong?

[prod3.test]> get pods | grep hub-user-a
hub-user-api-68f4d568c4-2xrnh                  1/1     Running   0          14h     192.168.219.86    kucalc-prod3-node-pnqj   <none>           <none>
hub-user-api-68f4d568c4-5b29d                  1/1     Running   0          14h     192.168.181.44    kucalc-prod3-node-pvcq   <none>           <none>
[prod3.test] > c log hub-user-api-68f4d568c4-5b29d | grep student481di2@schil
2020-01-28T11:48:10.220Z - debug: PostgreSQL._user_query(id=181ecc): "[{\"patches\":{\"string_id\":\"9af62934d83e0f2b6145a535c590685303b99cad\",\"time\":\"2020-01-28T11:48:10.041Z\",\"patch\":\"[1,[{\\\"email_address\\\":\\\"harald+student481di2@schil.ly\\\",\\\"table\\\"
:\\\"students\\\",\\\"student_id\\\":\\\"4632f47a-9b82-4a78-9604-537712e59100\\\"}]]\",\"user_id\":1,\"prev\":\"2020-01-28T11:47:59.781Z\",\"format\":1}}]"
2020-01-28T11:48:10.221Z - debug: PostgreSQL._user_query(id=e1e48d): "{\"patches\":{\"string_id\":\"9af62934d83e0f2b6145a535c590685303b99cad\",\"time\":\"2020-01-28T11:48:10.041Z\",\"patch\":\"[1,[{\\\"email_address\\\":\\\"harald+student481di2@schil.ly\\\",\\\"table\\\":
\\\"students\\\",\\\"student_id\\\":\\\"4632f47a-9b82-4a78-9604-537712e59100\\\"}]]\",\"user_id\":1,\"prev\":\"2020-01-28T11:47:59.781Z\",\"format\":1}}"
2020-01-28T11:48:10.221Z - debug: PostgreSQL.user_set_query(project_id='c37fbd83-c4c3-4f92-b66c-37b8d2c8cdf1', table='patches'): "{\"string_id\":\"9af62934d83e0f2b6145a535c590685303b99cad\",\"time\":\"2020-01-28T11:48:10.041Z\",\"patch\":\"[1,[{\\\"email_address\\\":\\\"h
arald+student481di2@schil.ly\\\",\\\"table\\\":\\\"students\\\",\\\"student_id\\\":\\\"4632f47a-9b82-4a78-9604-537712e59100\\\"}]]\",\"user_id\":1,\"prev\":\"2020-01-28T11:47:59.781Z\",\"format\":1}"
2020-01-28T11:48:11.507Z - debug: Client(49a8be52-3434-4eb0-b93b-fcc689430cb4).mesg_invite_noncloud_collaborators: inviting harald+student481di2@schil.ly
2020-01-28T11:48:11.511Z - debug: Client(49a8be52-3434-4eb0-b93b-fcc689430cb4).mesg_invite_noncloud_collaborators: user harald+student481di2@schil.ly doesn't have an account yet -- may send email (if we haven't recently)
2020-01-28T11:48:11.513Z - debug: PostgreSQL._query('SELECT invite#>'{"harald+student481di2@schil.ly"}' AS to FROM projects',id='23b37b'): "query='SELECT invite#>'{\"harald+student481di2@schil.ly\"}' AS to FROM projects WHERE project_id :: UUID = $1 (concurrent=1)'"
2020-01-28T11:48:11.516Z - debug: PostgreSQL._query('SELECT invite#>'{"harald+student481di2@schil.ly"}' AS to FROM projects',id='23b37b'): "done (concurrent=0) (query_time_ms=0) -- success"
2020-01-28T11:48:11.520Z - debug: Client(49a8be52-3434-4eb0-b93b-fcc689430cb4).mesg_invite_noncloud_collaborators: send_email invite to harald+student481di2@schil.ly
2020-01-28T11:48:11.520Z - debug: send_email(to:harald+student481di2@schil.ly) -- <p>Hello!</p>
2020-01-28T11:48:11.521Z - debug: send_email(to:harald+student481di2@schil.ly) -- sending email to harald+student481di2@schil.ly starting...
2020-01-28T11:48:11.521Z - debug: send_email(to:harald+student481di2@schil.ly) -- sending email to harald+student481di2@schil.ly -- data -- {"from":{"email":"invites@cocalc.com","name":"CoCalc"},"subject":"CoCalc Invitation to Course small","content":[{"type":"text/html",
"value":"<p>Hello!</p>\n<p>We will use CoCalc for the course <em>small</em>.</p>\n<p>Please sign up!</p>\n<p>--</p>\n<p>Harald Schilly</p>\n\n<br/><br/>\n<b>To accept the invitation:\n<ol>\n<li>Open <a href=\"https://test.cocalc.com/app\">CoCalc</a></li>\n<li>Sign up/in u
sing <i>exactly</i> your email address <code>harald+student481di2@schil.ly</code></li>\n<li>Open <a href='https://test.cocalc.com/projects/f556a09a-9f5b-421e-b05c-55f9ceda97b0/'>the project 'small'</a>.</li>\n</ol></b>\n<br/><br />\n(If you're already signed in via <i>ano
ther</i> email address,\n you have to sign out and sign up/in using the mentioned email address.)\n"}],"template_id":"0375d02c-945f-4415-a611-7dc3411e2a78","personalizations":[{"subject":"CoCalc Invitation to Course small","to":[{"email":"harald+student481di2@schil.ly"}]}
],"reply_to":{"name":"Harald Schilly","email":"hsy@sagemath.com"},"bcc":[{"email":"invites@cocalc.com"}],"categories":["invite"],"asm":{"group_id":699},"substitutions":{"#title#":"CoCalc Invitation to Course small"}}
2020-01-28T11:48:11.818Z - debug: send_email(to:harald+student481di2@schil.ly) -- sending email to harald+student481di2@schil.ly -- success -- undefined
2020-01-28T11:48:11.819Z - debug: send_email(to:harald+student481di2@schil.ly) -- successfully sent email
2020-01-28T11:48:11.819Z - debug: PostgreSQL._query('UPDATE projects',id='246f50'): "query='UPDATE projects SET invite=JSONB_SET(COALESCE(invite#>'{}', '{}'::JSONB), '{harald+student481di2@schil.ly}', (JSONB_SET(COALESCE(invite#>'{harald+student481di2@schil.ly}', '{}'::JS
ONB), '{time}', $1::JSONB) - 'error')) WHERE project_id :: UUID = $2 (concurrent=1)'"
[prod3.test] > c log hub-user-api-68f4d568c4-2xrnh | grep student481di2@schil
2020-01-28T11:48:08.962Z - debug: PostgreSQL.user_search: "query = \"harald+student481di2@schil.ly\\n\""
2020-01-28T11:48:11.474Z - debug: Client(39fb2157-5f20-49c0-9b9a-6fc5d90dfdf3).mesg_invite_noncloud_collaborators: inviting harald+student481di2@schil.ly
2020-01-28T11:48:11.478Z - debug: Client(39fb2157-5f20-49c0-9b9a-6fc5d90dfdf3).mesg_invite_noncloud_collaborators: user harald+student481di2@schil.ly doesn't have an account yet -- may send email (if we haven't recently)
2020-01-28T11:48:11.480Z - debug: PostgreSQL._query('SELECT invite#>'{"harald+student481di2@schil.ly"}' AS to FROM projects',id='ae4153'): "query='SELECT invite#>'{\"harald+student481di2@schil.ly\"}' AS to FROM projects WHERE project_id :: UUID = $1 (concurrent=1)'"
2020-01-28T11:48:11.481Z - debug: PostgreSQL._query('SELECT invite#>'{"harald+student481di2@schil.ly"}' AS to FROM projects',id='ae4153'): "done (concurrent=0) (query_time_ms=1) -- success"
2020-01-28T11:48:11.484Z - debug: Client(39fb2157-5f20-49c0-9b9a-6fc5d90dfdf3).mesg_invite_noncloud_collaborators: send_email invite to harald+student481di2@schil.ly
2020-01-28T11:48:11.484Z - debug: send_email(to:harald+student481di2@schil.ly) -- <p>Hello!</p>
2020-01-28T11:48:11.484Z - debug: send_email(to:harald+student481di2@schil.ly) -- sending email to harald+student481di2@schil.ly starting...
2020-01-28T11:48:11.484Z - debug: send_email(to:harald+student481di2@schil.ly) -- sending email to harald+student481di2@schil.ly -- data -- {"from":{"email":"invites@cocalc.com","name":"CoCalc"},"subject":"CoCalc Invitation to Course small","content":[{"type":"text/html",
"value":"<p>Hello!</p>\n<p>We will use CoCalc for the course <em>small</em>.</p>\n<p>Please sign up!</p>\n<p>--</p>\n<p>Harald Schilly</p>\n\n<br/><br/>\n<b>To accept the invitation:\n<ol>\n<li>Open <a href=\"https://test.cocalc.com/app\">CoCalc</a></li>\n<li>Sign up/in u
sing <i>exactly</i> your email address <code>harald+student481di2@schil.ly</code></li>\n<li>Open <a href='https://test.cocalc.com/projects/f556a09a-9f5b-421e-b05c-55f9ceda97b0/'>the project 'small'</a>.</li>\n</ol></b>\n<br/><br />\n(If you're already signed in via <i>ano
ther</i> email address,\n you have to sign out and sign up/in using the mentioned email address.)\n"}],"template_id":"0375d02c-945f-4415-a611-7dc3411e2a78","personalizations":[{"subject":"CoCalc Invitation to Course small","to":[{"email":"harald+student481di2@schil.ly"}]}
],"reply_to":{"name":"Harald Schilly","email":"hsy@sagemath.com"},"bcc":[{"email":"invites@cocalc.com"}],"categories":["invite"],"asm":{"group_id":699},"substitutions":{"#title#":"CoCalc Invitation to Course small"}}
2020-01-28T11:48:11.725Z - debug: send_email(to:harald+student481di2@schil.ly) -- sending email to harald+student481di2@schil.ly -- success -- undefined
2020-01-28T11:48:11.725Z - debug: send_email(to:harald+student481di2@schil.ly) -- successfully sent email
2020-01-28T11:48:11.725Z - debug: PostgreSQL._query('UPDATE projects',id='73917d'): "query='UPDATE projects SET invite=JSONB_SET(COALESCE(invite#>'{}', '{}'::JSONB), '{harald+student481di2@schil.ly}', (JSONB_SET(COALESCE(invite#>'{harald+student481di2@schil.ly}', '{}'::JS
ONB), '{time}', $1::JSONB) - 'error')) WHERE project_id :: UUID = $2 (concurrent=1)'"
haraldschilly commented 4 years ago

Guess what: k scale --replicas=1 deploy hub-user-api and I only get it once.

williamstein commented 4 years ago

My guess based on the above:

This is perhaps why testing with cc-in-cc it worked...

williamstein commented 4 years ago

Yes, this makes perfect sense, because if you do a write then read over a single connection in postgresql, it works as expected, but obviously not if you do it over two connections...

williamstein commented 1 week ago

hub-user-api doesn't exist anymore, so closing this.