-
-
Notifications
You must be signed in to change notification settings - Fork 495
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
fork inside context - Maximum call stack size exceeded #3338
Comments
Why are you even doing this? The default |
We are creating our own instance of AsyncLocalStorage and are switching context independent of any middleware. For example a task in our system has it's own context and can create a sub context if needed which eventually needs a new fork of mikro-orm. So we cannot use RequestContext as such but the context function as shown above. As the fork function is only called if some orm.em operation is called and there isn't already an EntityManager in this context, it is more efficient than directly creating one every time a new context is created. You are right, if i create the fork outside the context and return undefined inside the context as long as no fork is known, it would use the global instance without looping. Before the change it was possible to create a fork inside the context, now i need to use some kind of workaround. I think it would be enough to add an property in ForkOptions which disables the getContext call inside fork. Somewhat OT: |
Interesting, thanks for explaination.
Yeah we can definitely do something like that. Or have a recursion check will do the job as well. |
No problem, i think we are catching all the edge cases ... always 😢 I would prefer the option (noContext?), i find a recursion checks somewhat crazy/unpredictable. |
Yeah I know, but using new option can be quite confusing given we have the |
Btw you should also be able to get around by creating first fork outside of the |
If i create a fork outside of the method, it would call the context method which then tries to create a fork.... |
Lol right :D Lets just come up with some better name and do the option. Can be a bit longer, this is quite specific use case so better to have a descripitive name. |
Ideas: |
I like |
I think f7c1ef2 broke disableContextResolution as i get an "Maximum call stack size exceeded" again. It still takes "this" in line 1168 but then calls getContext when schema is retrieved in line 1187 which triggers the loop. |
Let me know if 5964e52 helps. |
Works again, thanks. |
Describe the bug
Since cc6d59b fork always calls getContext which calls the config function context if useContext is true on the used entity manager. This leads to a loop if fork is used from the global instance (which always has useContext true) inside the context function.
To Reproduce
The use of orm.em.fork inside the context function leads to "Maximum call stack size exceeded".
In my case 'Context' uses AsyncLocalStorage to store and retrieve several objects with some sort of type safety. orm.em.fork is called if the store does not already contains an EntityManager (first call).
Current workaround:
Versions
The text was updated successfully, but these errors were encountered: