nodeca / tabex

Cross-tab message bus for browsers.
http://nodeca.github.io/tabex/
MIT License
219 stars 19 forks source link

Locks are not being honored #8

Closed mvaled closed 8 years ago

mvaled commented 8 years ago

I'm opening the following page in two tabs and both report the "Lock acquired":

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Bug in tabex?</title>
    <script src="https://cdn.jsdelivr.net/jquery/1.11.1/jquery.min.js"></script>
    <script src="./tabex.js"></script>
    <script>
      $(function(){
      var ex = window.tabex.client();
      ex.lock('common', 1000, function(unlock){
          console.debug('Lock acquired');
      });
      });
    </script>
  </head>
  <body>
    <p>Open the console.</p>
  </body>
</html>

Environment:

Firefox 44, no private mode, I can confirm that localStorage events are being propagated between tabs.

puzrin commented 8 years ago

Can not reproduce. Try to increase timeout. Also note we have a couple of tests for locks https://github.com/nodeca/tabex/blob/1.0.3/test/client_iframe.js#L110-L146.

If you still think that bug exists - create a more detailed instruction how to reproduce, step-by-step. And check that tests are ok.

mvaled commented 8 years ago

I'll try to give further details... But I'm not familiar with the latest tools for testing js code...

I created a clip showing how I test it (I know it won't help much, but at least you can see what I'm doing). The clip is in https://youtu.be/50SzIix6tf4

Kirill89 commented 8 years ago

@mvaled, second parameter of .lock() is lifetime in milliseconds. On video we can see delay between two clicks about 3 seconds. Just set correct lifetime of lock.

mvaled commented 8 years ago

Then I got wrong the meaning of the lock primitive. I thought I would held the lock until I call the unlock function or the tab closes...

I thought the timeout was the timeout before giving up to get the lock not the time the lock was to be held.

My use case is similar to the one exposed in the README: keep a single long-polling connection to the server between tabs. But I didn't wan't to use the '!sys.master' signal because I thought that higher level primitives could be used for the task.