okTurtles / group-income

A decentralized and private (end-to-end encrypted) financial safety net for you and your friends.
https://groupincome.org
GNU Affero General Public License v3.0
331 stars 44 forks source link

Invalid negative reference count when deleting a chatroom #2277

Closed taoeffect closed 2 months ago

taoeffect commented 3 months ago

Problem

  1. Create a chatroom
  2. Delete it

Screenshot 2024-08-01 at 12 00 02 PM

Solution

Don't know how this snuck in...

corrideat commented 3 months ago

It looks like this issue was introduced by moving the call to /release into the leaveChatRoom file. This is most certainly incorrect, because that function is called 'optimistically' in the side-effect, meaning that it could potentially be called multiple times. In addition, it's better architecturally for the call to /release to be made by the group contract, as it's the one 'managing' references to the chatroom contract (i.e., the one that called /retain on it).

I see there were other changes related to reference counting (such as excluding ourselves). I see those were made to fix issues, but I'll investigate further as it shouldn't be needed to check for ourselves. These types of bugs (negative counts) can indicate issues with reference counting in general or faulty reference management logic. I'll be investigating these issues.