mx-puppet-bridge icon indicating copy to clipboard operation
mx-puppet-bridge copied to clipboard

wait for postgres, possibly fixes https://github.com/matrix-discord/mx-puppet-discord/issues/78

Open erulabs opened this issue 4 years ago • 8 comments

Hello!

This PR ensures that we always wait for postgres to be connected before we continue on in the code - this prevents a problem where getSchemaVersion fails, and then returns 0 as the schema version, which causes some thrashing of the database :( - this ensures we never run getSchemaVersion() until we know that query will fail for non-connection reasons. Rebooting a machine is a good example where postgres and the bridge will both start at the same time, which can lead to this issue.

I'm still testing to ensure that this 100% resolves https://github.com/matrix-discord/mx-puppet-discord/issues/78 (I think it will), but at any rate it's probably a good idea to ensure PG is ready before running :)

Thanks!

erulabs avatar Nov 11 '20 05:11 erulabs

Thanks for the PR, lint fails though (as seen at the failing CI) with

/home/travis/build/Sorunome/mx-puppet-bridge/src/store.ts:205:4 ERROR: 205:4 await-promise Invalid 'await' of a non-Promise value.

Sorunome avatar Nov 12 '20 13:11 Sorunome

sqlite doesn't return a promise for db.Open() so I went ahead and added a Promise.resolve() around db.Open in store such that it is always a promise, even if it isn't. Should fix the typescript lint (and probably also fix sqlite)

I've only tested this with postgres as in my setup we're always using psql, and never using sqlite. That said, I can confirm this does resolve a number of the schema issues!

erulabs avatar Jan 13 '21 01:01 erulabs

The multi-layer promise unpacking is so unintuitive, but ... Yeah, that hack should work.

Dessix avatar Jan 13 '21 01:01 Dessix

The CI says the unit tests are failing

Sorunome avatar Jan 17 '21 11:01 Sorunome

If you'd like, I've rebased this changeset to the latest upstream HEAD, applied the compilation fix I commented above, and pushed it to Dessix/mx-puppet-bridge/postgres-wait.

Dessix avatar Aug 20 '21 03:08 Dessix

@erulabs I received a message notification from you on a commit but it doesn't appear to have made it into this PR?

Additionally, my branch doesn't appear to actually succeed- I think it may be a problem with my build or test environments, but once I get to the await for Connect, my Node instance silently exits with status code 0. Can you confirm that your code - when merged with upstream - actually produces correct / expected behaviour? If so, that would indicate that it's actually my environment and I can work to simplify it further.

Dessix avatar Aug 24 '21 01:08 Dessix

@Dessix what's the status on your side? Since it does sound like a good feature.

dsonck92 avatar Dec 30 '21 10:12 dsonck92

@dsonck92 I had a repro but I couldn't figure out what was leading to Node exiting. Strace and node-debug (and even rr) gave me nothing at the point of failure. After 2 days at it, I ended up deciding to abandon my codebase rather than investigate it any further, and planned to rewrite it in Rust to avoid Node in the future.

Dessix avatar Dec 30 '21 16:12 Dessix