question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Missing PubSub messages when using connection ping

See original GitHub issue

### Expected behavior setPingConnectionInterval should send periodic ping messages and keep channels alive, but this must not affect any other type of messages on channels.

Actual behavior

When using setPingConnectionInterval some messages will not be delivered to listeners after being published. I have a test code which can reliably reproduce this issue:

import org.redisson.Redisson;
import org.redisson.api.RTopic;
import org.redisson.api.RedissonClient;
import org.redisson.codec.SerializationCodec;
import org.redisson.config.Config;
import org.redisson.config.SubscriptionMode;

import java.util.UUID;
import java.util.concurrent.ConcurrentSkipListSet;

public class PlainPubSubTest {

    public static void main(String[] args) throws InterruptedException {
        ConcurrentSkipListSet<String> sentItems = new ConcurrentSkipListSet<>();
        ConcurrentSkipListSet<String> receivedItems = new ConcurrentSkipListSet<>();

        System.out.println("Staring test");

        RedissonClient redissonClient = redissonClient(configSentinel());

        RTopic<String> eventsTopic = redissonClient.getTopic("eventsTopic");
        eventsTopic.addListener((channel, msg) -> receivedItems.add(msg));

        System.out.println("Starting sending loop");
        for(int i = 0; i<1000; i++){
            final String message = UUID.randomUUID().toString();
            eventsTopic.publish(message);
            sentItems.add(message);
            Thread.sleep(10);
        }

        System.out.println("Sent: " + sentItems.size() + ", got: " + receivedItems.size());
        Thread.sleep(1000);
        System.out.println("Sent: " + sentItems.size() + ", got: " + receivedItems.size());
    }

    private static RedissonClient redissonClient(Config config){
        return Redisson.create(config);
    }

    private static Config configSentinel(){
        Config config = new Config();
        config.setCodec(new SerializationCodec());
        String password = "*****************";
        String masterName = "my-master-name";
        String[] sentinelAddresses = new String[]{"redis://localhost:26001", "redis://localhost:26002", "redis://localhost:26003"};
        Integer connectionTimeout = 10000;
        int pingTimeout = 5000;
        int reconnectionTimeout = 5000;
        int connectionPoolSize = 10;
        int connectionPoolMinSize = 10;
        int connectionPingInterval = 50; //Changing to 0 eliminates issue
        config.useSentinelServers()
                .setPassword(password)
                .setMasterName(masterName)
                .addSentinelAddress(sentinelAddresses)
                .setConnectTimeout(connectionTimeout)
                .setPingTimeout(pingTimeout)
                .setPingConnectionInterval(connectionPingInterval)
                .setSubscriptionMode(SubscriptionMode.MASTER)
                .setFailedSlaveReconnectionInterval(reconnectionTimeout)
                .setMasterConnectionMinimumIdleSize(connectionPoolMinSize)
                .setMasterConnectionPoolSize(connectionPoolSize);
        return config;
    }
}

Output of this code will produce varying results each time, but it will never get all sent messages, like this:

Staring test
Starting sending loop
Sent: 1000, got: 640
Sent: 1000, got: 640

However if connectionPingInterval is set to 0 (disabled) issue is completely eliminated, like this:

Staring test
Starting sending loop
Sent: 1000, got: 1000
Sent: 1000, got: 1000

Redis version

redis_version:4.0.6
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:f1060815dd32471a
redis_mode:standalone
os:Linux 3.10.0-514.26.1.el7.x86_64 x86_64

Redisson version

3.7.2

Redisson configuration

Visible in test case

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:22 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
valodzkacommented, Nov 5, 2018

Also tested on clean linux (debian 9, 4.9.0-8-amd64, openjdk 11, redis 4.0.11, redission 3.0.0 branch). Not at every run, but very often gives the same: https://gist.github.com/valodzka/da427f73b2c6437460bc4be3b527ac45/revisions

1reaction
valodzkacommented, Nov 4, 2018

Same issue, not fixed.

I’m unable to reproduce it with current test

Thats weird. I created special project https://github.com/valodzka/redisson-issue-1497. Easily reproducible (like 80% times) for me at commit 7b20c0d9a55762ea86d1dd6505afbccd20d56079 with java 11 and java 8, redis 4 and redis 5 (mac os 10.13.6). Log example https://gist.github.com/valodzka/da427f73b2c6437460bc4be3b527ac45.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting | Cloud Pub/Sub Documentation
Learn about troubleshooting steps that you might find helpful if you run into problems using Pub/Sub. Cannot create a subscription.
Read more >
Why can I not PING when Subscribed using PUBSUB?
When a client subscribes, that connection is basically blocked for outgoing commands as it is used to listen for incoming messages. One possible ......
Read more >
Missing PubSub messages when using connection ping
Missing PubSub messages when using connection ping. ... Missing PubSub messages when using connection ping. Javascript Required. Kindly enable Javascript.
Read more >
PubSub | Twitch Developers
The Twitch PubSub system allows back-end services to broadcast realtime messages to clients. ... Example: PING Connection Message.
Read more >
Redis Pub/Sub
How to use pub/sub channels in Redis. ... Rather, published messages are characterized into channels, ... Pub/Sub has no relation to the key...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found