Posting to notifications returns a 500 error #73

Closed
opened 2022-08-19 10:29:36 +00:00 by Kura · 6 comments

Browser
grafik

Server log

Aug 19 10:28:50 mio npm[42684]: ERR  1        [api]        Internal error occurred in i/notifications: No such note.
Browser ![grafik](/attachments/c1c61e96-74e1-4add-907b-6cb70509d78c) Server log ``` Aug 19 10:28:50 mio npm[42684]: ERR 1 [api] Internal error occurred in i/notifications: No such note. ```
7.5 KiB
Owner

I tried reproducing this but couldn't so far.
Note that No such note. is the logger output, but there should also be a UUID (likely somewhere in the "console" area of your devtools, rather than the "network" component) - could I see which UUID is being thrown?

I tried reproducing this but couldn't so far. Note that `No such note.` is the logger output, but there should also be a UUID (likely somewhere in the "console" area of your devtools, rather than the "network" component) - could I see which UUID is being thrown?
Author

does that help?

vlc and mpv do play< this, my firefox doesnt. just as a notice.

also no uuid or anything logged as far as i can see

does that help? vlc and mpv do play< this, my firefox doesnt. just as a notice. also no uuid or anything logged as far as i can see
Owner

The No such note error message could be raised when the note a notification is referring to is deleted. But there is a foreign key constraint so if a note gets deleted, any notifications about it should get deleted as well.

The other explaination would be that the visibility check fails but I can also not imagine how that would happen. I don't think you should ever get any notifications about a note that you are not allowed to see?

If you (@kura) are feeling adventurous, you can try to check the notification table in the database and look at the next ~30 notifications after the last ones you could load and for those that have a noteId field set to something other than null if there is something strange going on. All those notes should in theory have a visibility where you are allowed to see them.

The `No such note` error message could be raised when the note a notification is referring to is deleted. But there is a foreign key constraint so if a note gets deleted, any notifications about it should get deleted as well. The other explaination would be that the visibility check fails but I can also not imagine how that would happen. I don't think you should ever get any notifications about a note that you are not allowed to see? If you (@kura) are feeling adventurous, you can try to check the `notification` table in the database and look at the next ~30 notifications after the last ones you could load and for those that have a `noteId` field set to something other than null if there is something strange going on. All those notes should in theory have a visibility where you are allowed to see them.
Owner

As I already pointed out in #143 what the error you showed initially may indicate is a database timeout.

I also noticed that there is currently no place in the code where notifications are deleted. This means all notifications remain in the database forever (unless deleted through database-internal mechanisms like foreign key constraints). Maybe we should delete notifications that have been read and are older than some threshold (maybe 1 year?).

As I already pointed out in #143 what the error you showed initially may indicate is a database timeout. I also noticed that there is currently no place in the code where notifications are deleted. This means all notifications remain in the database forever (unless deleted through database-internal mechanisms like foreign key constraints). Maybe we should delete notifications that have been read and are older than some threshold (maybe 1 year?).
Owner

I don't think you should ever get any notifications about a note that you are not allowed to see?

I think I have to retract this statement. You can e.g. receive notifications about someone renoting one of your notes. But since the renote itself was (somehow without being a quote?) made follower only you cannot see it. For this case I think we may want to adjust the visibility rules.


Further, you may run into problems when your relation to another user changes since visibility/following status is not tracked historically. Therefore, as soon as you unfollow someone you will no longer be able to see any notes from them. Example: They made a follower-only note. You replied to the note yourself. They reacted to the note, causing a notification.

Later you unfollow the other user (or they force-unfollow or block you). While the visibility algorithm allows you to see your own notes, it now determines that you cannot see the replied to note. While packing the notification this causes an error.

There are multiple things we could do to fix this. The easiest but slightly hacky way would be to catch the error and set the reply/renote that gets packed into the notification to null or something similar. Note that this would still reveal the renote/reply note id.

Alternatively we would have to check the visibility of all notifications relating to a particular pair of users whenever their "relation" changes.

> I don't think you should ever get any notifications about a note that you are not allowed to see? I think I have to retract this statement. You can e.g. receive notifications about someone renoting one of your notes. But since the renote itself was (somehow without being a quote?) made follower only you cannot see it. For this case I think we may want to adjust the visibility rules. --- Further, you may run into problems when your relation to another user changes since visibility/following status is not tracked historically. Therefore, as soon as you unfollow someone you will no longer be able to see any notes from them. Example: They made a follower-only note. You replied to the note yourself. They reacted to the note, causing a notification. Later you unfollow the other user (or they force-unfollow or block you). While the visibility algorithm allows you to see your own notes, it now determines that you cannot see the replied to note. While packing the notification this causes an error. There are multiple things we could do to fix this. The easiest but slightly hacky way would be to catch the error and set the reply/renote that gets packed into the notification to `null` or something similar. Note that this would still reveal the renote/reply note id. Alternatively we would have to check the visibility of all notifications relating to a particular pair of users whenever their "relation" changes.
Owner

As a workaround you can run this SQL query to clean up such notifications you should not have received:

DELETE FROM "notification" WHERE "noteId" IS NOT NULL AND NOT note_visible("noteId", "notifieeId");
As a workaround you can run this SQL query to clean up such notifications you should not have received: ```sql DELETE FROM "notification" WHERE "noteId" IS NOT NULL AND NOT note_visible("noteId", "notifieeId"); ```
Johann150 added the
fix
label 2022-12-23 10:32:08 +00:00
Sign in to join this conversation.
No Label
feature
fix
upkeep
No Milestone
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: FoundKeyGang/FoundKey#73
No description provided.