raisedragon / pircbotx

Automatically exported from code.google.com/p/pircbotx
0 stars 0 forks source link

Possible race while shutting down when channel has a key #239

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The thread which calls shutdown can sometime hang forever on 
org.pircbotx.Channel.getMode(Channel.java:127).  In the wild this seems to 
reproduce about 1 in 100 times for me.

What steps will reproduce the problem?
1. Connect to a channel with a key
2. trigger shutdown 
3. repeat

What is the expected output? What do you see instead?

Expected shutdown, instead shutdown thread hangs with the following stack trace:

at sun.misc.Unsafe.park(Native Method)
    -  waiting on java.util.concurrent.CountDownLatch$Sync@147a710c
    at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:836)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedInterruptibly(AbstractQueuedSynchronizer.java:997)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1304)
    at java.util.concurrent.CountDownLatch.await(CountDownLatch.java:231)
    at org.pircbotx.Channel.getMode(Channel.java:127)
    at org.pircbotx.Channel.getModeArgument(Channel.java:182)
    at org.pircbotx.Channel.getChannelKey(Channel.java:239)
    at org.pircbotx.PircBotX.shutdown(PircBotX.java:2872)

What version of the product are you using? On what operating system?

1.9 on OSX Oracle java. I can't tell if this is an issue in the dev branch, but 
it looks possible.

Please provide any additional information below.

This is my guess as to what happens:

It looks like shutdown is trying to get the channel modes after it has shutdown 
its connection to the server. getMode is "stale" so it does this:
       bot.sendRawLine("MODE " + getName());
        if (modeLatch == null || modeLatch.getCount() == 0)
            modeLatch = new CountDownLatch(1);
        //Wait for setMode to be called
        modeLatch.await();

However, sendRawLine just ignores messages if it is not connected, therefore no 
mode reply is ever decrements the latch.

Original issue reported on code.google.com by chris4...@gmail.com on 22 Apr 2015 at 3:06

GoogleCodeExporter commented 9 years ago
This was fixed in 2.0 by caching the key in the Channel object. 1.9 isn't 
really supported anymore and there isn't a way to backport the change. 

Original comment by Lord.Qua...@gmail.com on 23 Apr 2015 at 7:17