Skip to content

Fixes #789: Wait for DB type initialization before querying #1081

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

danielfrankcom
Copy link

This PR fixes #789 by storing the array types request for potential promise chaining, if a query occurs before the types have finished being retrieved.

As described by #789, queries which use sql.array() can fail if they use a fresh connection. This can be seen in the "Array of Date" test within this repository, if the test is run by itself (using ot()).

After some investigation/debugging, it looks like there is a race condition between the completion of the fetchArrayTypes method, and the scheduling of the subsequent query. In my debugger, I was able to see the call to execute proceed far enough that the typeArrayMap was not updated before the query types were processed. Shortly after this, the fetchArrayTypes method completed and updated the typeArrayMap, but it was already too late.

The reason the "Array of Date" test doesn't fail as part of the test suite is because the types are initialized by the other tests that run before it. This is a timing sensitive issue, and if a test that does not use array types runs first then the types get initialized without any problems.

Please note I've run npm build and included the generated code as part of this PR. I'm not sure if that is the recommended approach to PRs for this project, or if the generated code will be built as part of the release process. I'm happy to amend the change set if necessary. I couldn't find a CONTRIBUTING.md file or contributor instructions anywhere but it's possible I missed them.

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.

Wrong inferred array types when invoking sql.array() for the first time.
1 participant