Hi all,<div><br></div><div> While I was getting similar erroneous behaviour as reported in the list previously, I've tried to track the issue in the code and found a major issue.</div><div>In LocalStatus.py, LocalStatusSQLite.py,UIDMaps.py,</div>
<div>I'm seeing this pattern:</div><div><pre style="margin-top:0px;margin-bottom:0px;padding:0px;border:0px;font-size:12px;line-height:16px"><div class="line" id="LC25" style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Courier,monospace;margin:0px;padding:0px 0px 0px 10px;border:0px">
<span class="k" style="margin:0px;padding:0px;border:0px;font-weight:bold">class</span> <span class="nc" style="margin:0px;padding:0px;border:0px;color:rgb(68,85,136);font-weight:bold">LocalStatusFolder</span><span class="p" style="margin:0px;padding:0px;border:0px">(</span><span class="n" style="margin:0px;padding:0px;border:0px">BaseFolder</span><span class="p" style="margin:0px;padding:0px;border:0px">):</span></div>
<div class="line" id="LC26" style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Courier,monospace;margin:0px;padding:0px 0px 0px 10px;border:0px"> <span class="k" style="margin:0px;padding:0px;border:0px;font-weight:bold">def</span> <span class="nf" style="margin:0px;padding:0px;border:0px;color:rgb(153,0,0);font-weight:bold">__init__</span><span class="p" style="margin:0px;padding:0px;border:0px">(</span><span class="bp" style="margin:0px;padding:0px;border:0px;color:rgb(153,153,153)">self</span><span class="p" style="margin:0px;padding:0px;border:0px">,</span> <span class="n" style="margin:0px;padding:0px;border:0px">name</span><span class="p" style="margin:0px;padding:0px;border:0px">,</span> <span class="n" style="margin:0px;padding:0px;border:0px">repository</span><span class="p" style="margin:0px;padding:0px;border:0px">):</span></div>
<div class="line" id="LC26" style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Courier,monospace;margin:0px;padding:0px 0px 0px 10px;border:0px"><span class="p" style="margin:0px;padding:0px;border:0px"> [...]</span></div>
<div class="line" id="LC27" style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Courier,monospace;margin:0px;padding:0px 0px 0px 10px;border:0px"> <span class="bp" style="margin:0px;padding:0px;border:0px;color:rgb(153,153,153)">self</span><span class="o" style="margin:0px;padding:0px;border:0px;font-weight:bold">.</span><span class="n" style="margin:0px;padding:0px;border:0px">savelock</span> <span class="o" style="margin:0px;padding:0px;border:0px;font-weight:bold">=</span> <span class="n" style="margin:0px;padding:0px;border:0px">threading</span><span class="o" style="margin:0px;padding:0px;border:0px;font-weight:bold">.</span><span class="n" style="margin:0px;padding:0px;border:0px">Lock</span><span class="p" style="margin:0px;padding:0px;border:0px">()</span></div>
<div class="line" id="LC27" style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Courier,monospace;margin:0px;padding:0px 0px 0px 10px;border:0px"><span class="p" style="margin:0px;padding:0px;border:0px"><br>
</span></div><div class="line" id="LC27" style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Courier,monospace;margin:0px;padding:0px 0px 0px 10px;border:0px"><span class="p" style="margin:0px;padding:0px;border:0px"><span class="k" style="margin:0px;padding:0px;border:0px;font-weight:bold"> def</span> <span class="nf" style="margin:0px;padding:0px;border:0px;color:rgb(153,0,0);font-weight:bold">save</span>(<span class="bp" style="margin:0px;padding:0px;border:0px;color:rgb(153,153,153)">self</span>):</span></div>
<div class="line" id="LC27" style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Courier,monospace;margin:0px;padding:0px 0px 0px 10px;border:0px"><span class="p" style="margin:0px;padding:0px;border:0px"> <span class="k" style="margin:0px;padding:0px;border:0px;font-weight:bold">with</span> <span class="bp" style="margin:0px;padding:0px;border:0px;color:rgb(153,153,153)">self</span><span class="o" style="margin:0px;padding:0px;border:0px;font-weight:bold">.</span>savelock:</span></div>
<div class="line" id="LC27" style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Courier,monospace;margin:0px;padding:0px 0px 0px 10px;border:0px"><br></div><div class="line" id="LC27" style="color:rgb(51,51,51);margin:0px;padding:0px 0px 0px 10px;border:0px">
<font face="arial, helvetica, sans-serif">I wonder the initial intend, but as I understand it, each INSTANCE of the class will have its own lock/mutex, so the acquiring of the lock in the method will only prevent mutual access if the same instance is used in multiple thread.</font></div>
<div class="line" id="LC27" style="color:rgb(51,51,51);margin:0px;padding:0px 0px 0px 10px;border:0px"><font face="arial, helvetica, sans-serif">That means that such code:</font></div><div class="line" id="LC27" style="color:rgb(51,51,51);margin:0px;padding:0px 0px 0px 10px;border:0px">
<font face="arial, helvetica, sans-serif">x1 = LocalStatusFolder(name, repo)</font></div><div class="line" id="LC27" style="color:rgb(51,51,51);margin:0px;padding:0px 0px 0px 10px;border:0px"><font face="arial, helvetica, sans-serif">x2 = LocalStatusFolder(name, repo)</font></div>
<div class="line" id="LC27" style="color:rgb(51,51,51);margin:0px;padding:0px 0px 0px 10px;border:0px"><font face="arial, helvetica, sans-serif"># In Thread 1</font></div><div class="line" id="LC27" style="color:rgb(51,51,51);margin:0px;padding:0px 0px 0px 10px;border:0px">
<font face="arial, helvetica, sans-serif">x1.save()</font></div><div class="line" id="LC27" style="color:rgb(51,51,51);margin:0px;padding:0px 0px 0px 10px;border:0px"><font face="arial, helvetica, sans-serif"># In Thread 2</font></div>
<div class="line" id="LC27" style="color:rgb(51,51,51);margin:0px;padding:0px 0px 0px 10px;border:0px"><font face="arial, helvetica, sans-serif">x2.save() </font></div><div class="line" id="LC27" style="color:rgb(51,51,51);margin:0px;padding:0px 0px 0px 10px;border:0px">
<font face="arial, helvetica, sans-serif"><br></font></div><div class="line" id="LC27" style="color:rgb(51,51,51);margin:0px;padding:0px 0px 0px 10px;border:0px"><font face="arial, helvetica, sans-serif">is not protected (it's racy).</font></div>
<div class="line" id="LC27" style="color:rgb(51,51,51);margin:0px;padding:0px 0px 0px 10px;border:0px"><font face="arial, helvetica, sans-serif"><br></font></div><div class="line" id="LC27" style="color:rgb(51,51,51);margin:0px;padding:0px 0px 0px 10px;border:0px">
<font face="arial, helvetica, sans-serif">I think the intend was to protect against all instance access to the local status folder, that is, the "savelock" must be a static member of the class.</font></div><div class="line" id="LC27" style="color:rgb(51,51,51);margin:0px;padding:0px 0px 0px 10px;border:0px">
<font face="arial, helvetica, sans-serif">In Python, it should be declared and used like this:</font></div><div class="line" id="LC27" style="margin:0px;padding:0px 0px 0px 10px;border:0px"><pre style="margin-top:0px;margin-bottom:0px;padding:0px;border:0px">
<div class="line" id="LC25" style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Courier,monospace;margin:0px;padding:0px 0px 0px 10px;border:0px"><span class="k" style="margin:0px;padding:0px;border:0px;font-weight:bold">class</span> <span class="nc" style="margin:0px;padding:0px;border:0px;color:rgb(68,85,136);font-weight:bold">LocalStatusFolder</span><span class="p" style="margin:0px;padding:0px;border:0px">(</span><span class="n" style="margin:0px;padding:0px;border:0px">BaseFolder</span><span class="p" style="margin:0px;padding:0px;border:0px">):</span></div>
<div class="line" id="LC25" style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Courier,monospace;margin:0px;padding:0px 0px 0px 10px;border:0px"><span class="p" style="margin:0px;padding:0px;border:0px"> savelock = threading.Lock() # Notice it's out of the init method</span></div>
<div class="line" id="LC26" style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Courier,monospace;margin:0px;padding:0px 0px 0px 10px;border:0px"> <span class="k" style="margin:0px;padding:0px;border:0px;font-weight:bold">def</span> <span class="nf" style="margin:0px;padding:0px;border:0px;color:rgb(153,0,0);font-weight:bold">__init__</span><span class="p" style="margin:0px;padding:0px;border:0px">(</span><span class="bp" style="margin:0px;padding:0px;border:0px;color:rgb(153,153,153)">self</span><span class="p" style="margin:0px;padding:0px;border:0px">,</span> <span class="n" style="margin:0px;padding:0px;border:0px">name</span><span class="p" style="margin:0px;padding:0px;border:0px">,</span> <span class="n" style="margin:0px;padding:0px;border:0px">repository</span><span class="p" style="margin:0px;padding:0px;border:0px">):</span></div>
<div class="line" id="LC26" style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Courier,monospace;margin:0px;padding:0px 0px 0px 10px;border:0px"><span class="p" style="margin:0px;padding:0px;border:0px"> [...]</span></div>
<div class="line" id="LC27" style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Courier,monospace;margin:0px;padding:0px 0px 0px 10px;border:0px"> <span class="bp" style="margin:0px;padding:0px;border:0px;color:rgb(153,153,153)">self</span><span class="o" style="margin:0px;padding:0px;border:0px;font-weight:bold">.</span><span class="n" style="margin:0px;padding:0px;border:0px">savelock</span> <span class="o" style="margin:0px;padding:0px;border:0px;font-weight:bold">=</span> <span class="n" style="margin:0px;padding:0px;border:0px">threading</span><span class="o" style="margin:0px;padding:0px;border:0px;font-weight:bold">.</span><span class="n" style="margin:0px;padding:0px;border:0px">Lock</span><span class="p" style="margin:0px;padding:0px;border:0px">()</span></div>
<div class="line" id="LC27" style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Courier,monospace;margin:0px;padding:0px 0px 0px 10px;border:0px"><span class="p" style="margin:0px;padding:0px;border:0px"><br>
</span></div><div class="line" id="LC27" style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Courier,monospace;margin:0px;padding:0px 0px 0px 10px;border:0px"><span class="p" style="margin:0px;padding:0px;border:0px"><span class="k" style="margin:0px;padding:0px;border:0px;font-weight:bold"> def</span> <span class="nf" style="margin:0px;padding:0px;border:0px;color:rgb(153,0,0);font-weight:bold">save</span>(<span class="bp" style="margin:0px;padding:0px;border:0px;color:rgb(153,153,153)">self</span>):</span></div>
<div class="line" id="LC27" style="font-family:Consolas,'Liberation Mono',Courier,monospace;margin:0px;padding:0px 0px 0px 10px;border:0px"><span class="p" style="margin:0px;padding:0px;border:0px"><font color="#333333"> </font><span class="k" style="color:rgb(51,51,51);margin:0px;padding:0px;border:0px;font-weight:bold">with</span><font color="#333333"> </font><font color="#999999">LocalStatusFolder</font><span class="o" style="color:rgb(51,51,51);margin:0px;padding:0px;border:0px;font-weight:bold">.</span><font color="#333333">savelock: # Notice the use of the class name and not self</font></span></div>
<div style="color:rgb(51,51,51)"><span class="p" style="margin:0px;padding:0px;border:0px"><br></span></div><div style="color:rgb(51,51,51)"><font face="arial, helvetica, sans-serif">I've not tracked where the instance of the LocalStatusFolder are used, but you probably know better than me, but I think the corruption of the local status folder reported by some user are caused by this.</font></div>
<div style="color:rgb(51,51,51)"><font face="arial, helvetica, sans-serif">The same applies the other files as well.</font></div><div style="color:rgb(51,51,51)"><font face="arial, helvetica, sans-serif"><br></font></div>
<div style="color:rgb(51,51,51)"><font face="arial, helvetica, sans-serif">Best regards,</font></div><div style="color:rgb(51,51,51)"><font face="arial, helvetica, sans-serif">X</font></div><div style="color:rgb(51,51,51)">
<font face="arial, helvetica, sans-serif"><br></font></div></pre></div></pre></div>