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

Bind context where it was lost #275

Closed
wants to merge 2 commits into from
Closed

Bind context where it was lost #275

wants to merge 2 commits into from

Conversation

desaroger
Copy link

I had issues (loopback#2597, loopback#2603) where I was losing context.

One solution was the usage of cls-hooked instead of cls on loopback-context as proposed by @josieusa here and that solved the issue. But when using the mongo connector, sometimes the context was losing.

I propose to patch two functions with context if available. For me this solve all my issues. I don't know if this will have downsides, but for me works always fine and all tests are passed.

PS: This is my first PR and english isn't my first language, so sorry if there are some mistakes. 😅

@slnode
Copy link

slnode commented Aug 11, 2016

Can one of the admins verify this patch?

@slnode
Copy link

slnode commented Aug 11, 2016

Can one of the admins verify this patch? To accept patch and trigger a build add comment ".ok\W+to\W+test."

@slnode
Copy link

slnode commented Aug 11, 2016

Can one of the admins verify this patch?

@codyolsen
Copy link

@desaroger Thanks for your work on this! You've pointed me in the right direction towards a fix!

@desaroger
Copy link
Author

@codyolsen there is a plan to solve this issue in a near future and merge with master? We are using this package with the PR and I will more comfortable if it could has master installed.

My fix it's the way to solve this kind of issue or you are thinking in another form? I am fixing this kind of issue on some libraries and I am interested on learn about process.context, cls, etc.

Thanks for your response 👯

@desaroger
Copy link
Author

I found another point where the context was losing, when updating a model through related model. I pushed another commit to this PR.

@bajtos
Copy link
Member

bajtos commented Aug 16, 2016

I'll leave the review to @raymondfeng, @superkhau and other maintainers of this repository.

However, I personally think this patch should be rejected. We should not be monkey-patching our code like this to support CLS. Instead, the fix should be implemented in the MongoDB client library we are using under the hood. Since cls-hooked is based on AsyncWrap that's becoming the standard part of Node.js core, I expect it's fair to ask the MongoDB client to play nicely with AsyncWrap. The same way how it already supports domains.

@desaroger
Copy link
Author

@bajtos yes I think the same, this was a desperate patch to not break our deadline.

I am a developer on Hooptap (we are using Bluemix and we are on IBM Global Entrepreneur), and our deadline is near and we needed to solve this as soon as possible, so we are using the patched version of this connector.

You know how long we would be talking until this is resolved? I am not comfortable with the idea of using my patched version instead of a official correctly-solved branch.

@superkhau
Copy link
Contributor

I agree with @bajtos, this is definitely going in the wrong direction. However, @raymondfeng should have the final say here.

@jannyHou
Copy link
Contributor

jannyHou commented Oct 6, 2016

@desaroger Sorry to say that this is not a proper solution on loopback side.
Considering your requirement, could you fork our repo and commit your workaround?
Thanks for understanding.

@slnode
Copy link

slnode commented Oct 6, 2016

Can one of the admins verify this patch?

@jannyHou
Copy link
Contributor

I am closing it now. Please feel free to reopen it when further discussion needed. Thanks for understanding.

@bajtos
Copy link
Member

bajtos commented Jan 9, 2017

Place for further discussions: strongloop/loopback-context#21

mrfelton pushed a commit to fullcube/loopback-connector-mongodb that referenced this pull request Jul 12, 2017
mrfelton pushed a commit to fullcube/loopback-connector-mongodb that referenced this pull request Jul 13, 2017
@pbalan
Copy link

pbalan commented Mar 7, 2018

@desaroger I tried your patch, but it doesn't work. Can you try help me here.

@desaroger
Copy link
Author

Hi @pbalan. It was more than a year ago when I did this patch, was a bad idea to use it then and I am sure there is better solutions out there now, please check them out.

Even so, if you insist on using this patch, probably doesn't work because some change on the library since I made this patch loses the context. I would recommend you check this PR code, basically I patch any function inside .map, .foreach etc. Try to find the line where you lost your context (on the updated version of the library) and add the patch there.

JonnyBGod added a commit to fullcube/loopback-connector-mongodb that referenced this pull request May 1, 2019
JonnyBGod added a commit to fullcube/loopback-connector-mongodb that referenced this pull request Dec 11, 2019
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.

9 participants