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

fix(medusa): Product repo typeorm issues #4084

Merged
merged 30 commits into from
May 16, 2023
Merged

fix(medusa): Product repo typeorm issues #4084

merged 30 commits into from
May 16, 2023

Conversation

adrien2p
Copy link
Member

@adrien2p adrien2p commented May 12, 2023

What
Type orm query strategy executes each separate query in a separate connection which exhaust the max connections allowed. Now it works again as it use to work. The perf should not be impacted

FIXES CORE-1388

@changeset-bot
Copy link

changeset-bot bot commented May 12, 2023

🦋 Changeset detected

Latest commit: 4aa42bb

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 10 packages
Name Type
@medusajs/medusa Patch
@medusajs/admin-ui Patch
@medusajs/admin Patch
@medusajs/medusa-js Patch
medusa-payment-paypal Patch
medusa-payment-stripe Patch
medusa-plugin-restock-notification Patch
medusa-react Patch
@medusajs/medusa-oas-cli Patch
@medusajs/oas-github-ci Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented May 12, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
medusa-docs ⬜️ Ignored (Inspect) Visit Preview May 16, 2023 7:07am

@adrien2p adrien2p marked this pull request as ready for review May 12, 2023 16:21
@adrien2p adrien2p requested a review from a team as a code owner May 12, 2023 16:21
@adrien2p
Copy link
Member Author

Need to do some little cleanup and fix the batch job integration

@SGFGOV
Copy link
Contributor

SGFGOV commented May 15, 2023 via email

@adrien2p
Copy link
Member Author

Hi.. is this done? Will this solve the too many connections issue?

On Sun, 14 May, 2023, 15:30 Adrien de Peretti, @.> wrote: Need to do some little cleanup and fix the batch job integration — Reply to this email directly, view it on GitHub <#4084 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXEQJHBPZ6YWZXKSTB3IEKDXGCUKPANCNFSM6AAAAAAX7LBXGM . You are receiving this because you are subscribed to this thread.Message ID: @.>
-- This message (including any attachments) may contain confidential, proprietary, privileged and/or private information. The information is intended to be for the use of the individual or entity designated above. If you are not the intended recipient of this message, please notify the sender immediately, and delete the message and any attachments. Any disclosure, reproduction, distribution or other use of this message or any attachments by an individual or entity other than the intended recipient is prohibited.

@SGFGOV It is almost done, I need to do some cleanup and fix the batch jobs. It should fix the idle in transaction queries that typeorm seams to not handle properly due to some internal bugs in their package

@adrien2p
Copy link
Member Author

I ve succeeded to maintain nice perf while not blocking the db

image

Copy link
Contributor

@riqwan riqwan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice cleanup!

Looks good, overall. I'll refrain from approving since I worked on this partially as well.

@adrien2p
Copy link
Member Author

/snapshot-this

@github-actions
Copy link
Contributor

🚀 A snapshot release has been made for this PR

Test the snapshots by updating your package.json with the newly published versions:

yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]

Latest commit: 7da6cc9

Copy link
Contributor

@olivermrbl olivermrbl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice work! Added a couple of comments

Copy link
Contributor

@olivermrbl olivermrbl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice work! Added a couple of comments

Copy link
Contributor

@olivermrbl olivermrbl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Just need the CI to turn green 💪

@adrien2p
Copy link
Member Author

@olivermrbl eveything is green now :)

@adrien2p
Copy link
Member Author

just running some more test before we merge

@adrien2p
Copy link
Member Author

adrien2p commented May 15, 2023

after some more deep tests, I decided to remove the query strategy completely. We loose in performance but at least we can be sure that it works no matter the concurrency. Te metrics below does not include the work on the prices in another pr

Screenshot 2023-05-15 at 17 18 36

@olivermrbl
Copy link
Contributor

@adrien2p – feel free to merge as you please :)

@adrien2p adrien2p merged commit 9518efc into develop May 16, 2023
@github-actions github-actions bot mentioned this pull request May 16, 2023
@SGFGOV
Copy link
Contributor

SGFGOV commented May 16, 2023

I know this isn't a medusa issue, but if the transaction fails and a rollback is issued the server crashes here inside the entity as it
doesn't get a connection
here
try {
await queryRunner.startTransaction(isolation);
const result = await runInTransaction(queryRunner.manager);
await queryRunner.commitTransaction();
return result;
}
catch (err) {
try {
// we throw original error even if rollback thrown an error
await queryRunner.rollbackTransaction(); <----- IT CRASHES HERE
}
catch (rollbackError) { }
throw err;
}
finally {
if (!this.queryRunner)
// if we used a new query runner provider then release it
await queryRunner.release();
}

@adrien2p
Copy link
Member Author

@SGFGOV if you have a query runner already released issue it means that you are having a flow that is not wrapped in a transaction and you don’t have called the service using withTransaction. Therefore in concurrent requests your requests qre sharing the same manager and therefore once it is released the next one can’t use it anymore. Is that your case or is it about something else?

@SGFGOV
Copy link
Contributor

SGFGOV commented May 16, 2023

@adrien2p , thanks for the prompt reply, here is the full error.

sorry, too many clients already
error: sorry, too many clients already
at Parser.parseErrorMessage (/node_modules/pg-protocol/dist/parser.js:287:98)
at Parser.handlePacket (/node_modules/pg-protocol/dist/parser.js:126:29)
at Parser.parse (/node_modules/pg-protocol/dist/parser.js:39:38)
at Socket. (/node_modules/pg-protocol/dist/index.js:11:42)
at Socket.emit (node:events:526:28)
at Socket.emit (node:domain:475:12)
at addChunk (node:internal/streams/readable:315:12)
at readableAddChunk (node:internal/streams/readable:289:9)
at Socket.Readable.push (node:internal/streams/readable:228:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
at TCP.callbackTrampoline (node:internal/async_hooks:130:17) {
length: 85,
severity: 'FATAL',
code: '53300',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'proc.c',
line: '357',
routine: 'InitProcess'
}

@adrien2p
Copy link
Member Author

@SGFGOV have you been able to test with the develop branch ? I didn’t ran i to this issue. What is the max number of connections you have configured?

@SGFGOV
Copy link
Contributor

SGFGOV commented May 16, 2023

I have configured a pool size of 100 which I think is the default

@adrien2p
Copy link
Member Author

Could you give a try with develop?

@SGFGOV
Copy link
Contributor

SGFGOV commented May 16, 2023 via email

@SGFGOV
Copy link
Contributor

SGFGOV commented May 16, 2023 via email

@adrien2p
Copy link
Member Author

adrien2p commented May 16, 2023

@SGFGOV what is the request you made? It seams that there is weird select that have been inserted in the query
product.0, product.1, product.2, product.3, product.4, product.5, product.6, product.7, product.8, product.9, product.10, product.11, product.12, product.13, product.14, product.15, product.16, product.17, product.18, product.19, product.20, product.21, product.22, product.23, product.24

@SGFGOV
Copy link
Contributor

SGFGOV commented May 16, 2023 via email

@adrien2p
Copy link
Member Author

When you look at your error, you have the query that fail, and in that query, in the SELECT statement you can see that there is those product.0 etc in it which might come from somewhere but I don't know where. What are you running to get this error?

@SGFGOV
Copy link
Contributor

SGFGOV commented May 16, 2023 via email

@SGFGOV
Copy link
Contributor

SGFGOV commented May 21, 2023

@adrien2p ..thanks a ton. I got it to work.the issue was the way the query was being prepared.

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.

4 participants