-
Notifications
You must be signed in to change notification settings - Fork 94
acquire_token not thread-safe #123
Comments
Thanks for the report. We will take a look into this. |
Hi @ace-e4s , when triaging issues, we would normally want to have the error/exception trace to debug. Since we don't have them this time, we manage to come up with a tentative fix based on limited information but won't know for sure it would address your scenario. You can grab it by |
I'll try to do some testing later today and let you know. |
@ace-e4s thanks for your prompt response and willing to help! We are planning a new release soon, so we will like to have this fix ready before that. |
Btw, I did some testing today, attempting to isolate and consistently reproducing the issue. I will do some more tomorrow and return to you. |
@ace-e4s FYI: there is an upcoming release 0.5.1 at PR 127, which does NOT include this pending fix (yet?). |
Hi, I'm running v0.5.0 of adal, btw. Case 1: our own code that uses adal run in parallell with memory_profiler on:
|
@ace-e4s Thanks! Good to see the trace! So the tentative fix that I mentioned 5 days ago was indeed targetting at the same line. By saying "I'm running v0.5.0", I assume you mean the official v0.5.0 (installed by |
@rayluo : After some extensive testing, it appears that the issue is related to use of memory_profiler. I'm not able to recreate the issue without the memory profiling turned on. How and why that can be the case, I'm not sure. Based on that, It seems like your code was ok all along. I see no reason to merge the proposed branch into trunk. Anyway, thanks for your quick response :) Cheers 🥇 |
Here comes even quicker response :) @ace-e4s : Thanks for your new information, which actually explains. While I have not personally used If you don't mind, I would suggest you to grab the aforementioned tentative fix, and then rerun your test under SAME |
I have now tested the fix, and it seems to remedy the situation as far as I can see. That said, the fix adresses the symptom. The fix "acknowledges" that the lock you have put may have been lifted for some reason, and then tries to remedy the situation by returning a default None to the pop. Furthermore, a side effect with the fix may be that it also mask potential exception/issues you would like to bubble up to the surface. What I don't understand is why the lock appears to be lifted in the first place?! It doesn't make any sense. Maybe this is just an undesired side effect (bug?) of the memory_profiler? The call is yours at the end of the day. What do you think? |
Here is the reason. The lock is inside the lower level cache.remove(), that lock has NOT been "lifted". However, it is the higher level _refresh_entry_if_necessary() uses this pattern "search cached token; oh it is stale, let's remove it", and that search-and-then-delete logic is not within a lock. I do have something in mind and plan to rewrite this cache logic completely in the future, but for now, the proposing patch is good enough. And nope, it won't mask any other exceptions. I'll include that patch into the upcoming release. |
The acquire_token method is not thread-safe.
Example:
The text was updated successfully, but these errors were encountered: