Hi,

I tested your code in multi-node scenario, and semaphore is released fine
when node owning a permit has been closed. In your code sample there is
only one node, and in this case semaphore is not released. I think that
"acquire" method should throw an exception in this case (say,
InterruptedException) as semaphore is no longer accessible when node is
stopped.

Vladislav,
I know you worked on distributed semaphore. Could you please share your
thoughts on the matter? And would you mind fixing that for a single-node
scenario?

Vladimir.

On Sun, Feb 28, 2016 at 11:14 PM, nyname00 <mario.st...@panagenda.com>
wrote:

> Hi Igniters,
>
> I've got a problem with a semaphore that seems to wait for a permit even if
> the node is already shut down. This behavior appears in a multi-node setup
> where i try to shut down all nodes at the same time (using a poison-pill).
> The code below can be used to reproduce the behavior. You will notice that
> there is no call on sem1#release() - this is because in my poison-pill
> scenario there seems to be no way to get a handle to sem1. And since I was
> under the impression that any semaphore gets released by Ignite when the
> node crashes/is shut down, I was expecting an exception on sem2#acquire().
>
> Any ideas? Best regards,
> Mario
>
> public static void main(String[] args) {
>         Ignite i1 = Ignition.start(new
> IgniteConfiguration().setGridName("1"));
>
>         System.out.println(">>> I1 STARTED");
>         IgniteSemaphore sem1 = i1.semaphore("sem1", 1, true, true);
>         System.out.println(">>> S1 READ");
>         sem1.acquire();
>         System.out.println(">>> S1 ACQUIRED");
>
>         new Thread(() -> {
>             IgniteSemaphore sem2 = i1.semaphore("sem1", 1, true, true);
>             System.out.println(">>> S1 READ 2");
>             sem2.acquire();
>             try {
>                 System.out.println(">>> S1 ACQUIRED 2");
>             } finally {
>                 sem2.release();
>             }
>         }).start();
>
>         try {
>             TimeUnit.SECONDS.sleep(2);
>         } catch (InterruptedException e) {
>             e.printStackTrace();
>         }
>
>         System.out.println(">>> I1 CLOSING");
>         i1.close();
>         System.out.println(">>> I1 CLOSED");
>     }
>
>
>
> --
> View this message in context:
> http://apache-ignite-users.70518.x6.nabble.com/Semaphore-waiting-for-permit-even-if-node-is-shut-down-tp3232.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.
>

Reply via email to