Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to typeorm 0.3.x #45

Merged
merged 11 commits into from
Dec 29, 2023
Merged

Update to typeorm 0.3.x #45

merged 11 commits into from
Dec 29, 2023

Conversation

javiercr
Copy link
Contributor

@javiercr javiercr commented Dec 26, 2023

Context

We've identified that often the cause of the "Waiting for this message" problem is an error when decrypting the message node and calling either to repository.decryptGroupMessage or repository.decryptMessage.

The actual error in this scenario is The database connection is not open.

Both decryptGroupMessage and decryptMessage need to call the signal storage:

The signal storage we're providing to Baileys is a backed by a typeorm sqlite database connection, therefore the actual error (The database connection is not open) comes from platform-whatsapp -> typeorm -> better-sqlite3.

Description

We still don't know the actual cause of the database connection not being initialized when baileys / libsignal need to talk to it. However typeorm 0.3.0 replaced the Connection abstraction with a new DataSource class.

This PR bumps typeorm from 0.2.41 to 0.3.17 with the hope that some of the latest changes in typeorm could help mitigate the db connection problem.

Even if this doesn't solve the problem described, given the amount of breaking changes in typeorm from 0.2.x to 0.3.x I do think it's worth it updating now to avoid problems in the future.

Summary of relevant changes:

  • Rename Connection to DataSource
  • Rename findOne({ id }) to findOneBy({ id }) and findOneOrFail({ id }) to findOneByOrFail({ id })
  • Add missing where key to find() args
  • Use findOne with a (mandatory) where clause
  • Replace db.close with ds.destroy

@KishanBagaria
Copy link
Member

lol tried running this and then

fish: Job 1, '/Applications/Texts.app/Content…' terminated by signal SIGSEGV (Address boundary error)

@javiercr
Copy link
Contributor Author

lol tried running this and then

fish: Job 1, '/Applications/Texts.app/Content…' terminated by signal SIGSEGV (Address boundary error)

fish: Job 1, '/Applications/Texts.app/Content…' terminated by signal SIGSEGV (Address boundary error)

it's actually a virus, got all your passwords now. jk, that's weird, let me test it with a production build, I just tested it in dev mode and opened the PR to document the thing.

@javiercr
Copy link
Contributor Author

javiercr commented Dec 26, 2023

uhm, it's working fine for me (build branch > run production Texts.app > load the platform externally > restart).

@javiercr
Copy link
Contributor Author

javiercr commented Dec 26, 2023

nvm, actually it crash when selecting a thread 🫥 (platform loaded externally)

@KishanBagaria
Copy link
Member

its alright tho im using the dev environ w webpack to run this, no issues so far.

gonna run https://github.com/TextsHQ/platform-tests

@javiercr
Copy link
Contributor Author

The same tests are failing in main than in this branch:

  Failed Tests: There were 4 failures

    sendMessage: image

      ✖ EntityNotFoundError: Could not find any entity of type "DBMessage" matching: { "id": "3EB02D261D573CF293EA|1", "threadID": "[email protected]" }


    deleteMessage

      ✖ Error: Message not found


    sendMessage: image

      ✖ EntityNotFoundError: Could not find any entity of type "DBMessage" matching: { "id": "3EB012CBE2602020EB3D|1", "threadID": "[email protected]" }


    deleteMessage

      ✖ Error: Message not found


  total:     30
  passing:   26
  failing:   4
  duration:  3.8s

Gonna dig into this errors, but this is unrelated to the PR

@KishanBagaria
Copy link
Member

yep i described the issue here: https://linear.app/texts/issue/PLT-1033/whatsapp-sent-messages-arent-saved-in-db-before-return - a simple sleep fixes it

@javiercr
Copy link
Contributor Author

In case anyone else want to test this, here is a build of this branch that can be easily installed:

CMD + J > Install platform integrations > Manifest URL:
https://drive.google.com/uc?id=1WZ0gyXRoTBpI6fpUV1KqR3CrEmWB2ui2

* Add `node` to `FullBaileysMessage` (message.original`)

* When calling `fetchMessages` send a retry request for any message that was not decrypted before

* Bump baileys
@javiercr
Copy link
Contributor Author

javiercr commented Dec 29, 2023

This now includes #47 (which was pointing to this branch). @KishanBagaria let me know if you're happy to merge this as well.

@javiercr javiercr changed the title Update to typeorm 0.3.x [do not merge] Update to typeorm 0.3.x Dec 29, 2023
@KishanBagaria
Copy link
Member

yep hasn't broken for me yet

@javiercr javiercr merged commit 7df831b into main Dec 29, 2023
2 checks passed
@javiercr javiercr deleted the javi/typeorm-0-3-x branch December 29, 2023 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants