spullara / redis-protocol

Java client and server implementation of Redis
356 stars 134 forks source link

Replies never received after previous transaction discarded #20

Closed jencompgeek closed 11 years ago

jencompgeek commented 11 years ago

In RedisClientBase.discard(), the txReplies queue is not cleared. This causes Reply gets to hang on next transaction. For example, testMultiDiscard hangs on the last line of testMultiExec:

private RedisClient client;

@Before
public void setUp() throws Exception {
    client = new RedisClient("localhost", 6379);
}

@Test
public void testMultiDiscard() throws Exception {
    client.set("testitnow", "willdo");
    client.multi();
    client.pipeline().set("testitnow", "notok");
    client.discard();
    assertEquals("willdo", new String(client.get("testitnow").data()));
    // Ensure we can run a new tx after discarding previous one
    testMultiExec();
}

@Test
public void testMultiExec() throws Exception {
    client.multi();
    ListenableFuture<StatusReply> reply = client.pipeline().set("key", "value");
    client.exec();
    assertEquals("OK",reply.get().data());
}
spullara commented 11 years ago

This appears to be a race condition in discard(). I have added your test and am looking at a couple of different solutions.