Fixes #789: Wait for DB type initialization before querying #1081
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 (usingot()
).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 toexecute
proceed far enough that thetypeArrayMap
was not updated before the query types were processed. Shortly after this, thefetchArrayTypes
method completed and updated thetypeArrayMap
, 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 aCONTRIBUTING.md
file or contributor instructions anywhere but it's possible I missed them.