Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proper creation of AttributeKey #2111

Closed
PedroMPagani opened this issue Jun 6, 2022 · 10 comments
Closed

Proper creation of AttributeKey #2111

PedroMPagani opened this issue Jun 6, 2022 · 10 comments
Labels
type: bug A general bug
Milestone

Comments

@PedroMPagani
Copy link

PedroMPagani commented Jun 6, 2022

Bug Report

I can't seem to find anyone talking about this.

Current Behavior

Currently when restarting my application this happens, even tho I am calling the .shutdown in the redisClient, no exception is print, its almost as if the client did succeed at the shutdown but maybe the netty is still keeping the URI there?

        at dev.goliath.libs.lettuce.core.RedisClient.connectStatefulAsync(RedisClient.java:310) ~[Core-1.0.1.jar:?]
        at dev.goliath.libs.lettuce.core.RedisClient.connectStandaloneAsync(RedisClient.java:287) ~[Core-1.0.1.jar:?]
        at dev.goliath.libs.lettuce.core.RedisClient.connect(RedisClient.java:216) ~[Core-1.0.1.jar:?]
        at donutsmp.goliath.core.messenger.RedisMessenger.<init>(RedisMessenger.java:40) ~[Core-1.0.1.jar:?]
        at donutsmp.goliath.core.Core.onEnable(Core.java:53) ~[Core-1.0.1.jar:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264) ~[pufferfish-api-1.18.2-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:370) ~[pufferfish-api-1.18.2-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:541) ~[pufferfish-api-1.18.2-R0.1-SNAPSHOT.jar:?]
        at com.rylinaux.plugman.util.PluginUtil.load(PluginUtil.java:309) ~[PlugManX.jar:?]
        at com.rylinaux.plugman.util.PluginUtil.load(PluginUtil.java:267) ~[PlugManX.jar:?]
        at com.rylinaux.plugman.util.PluginUtil.reload(PluginUtil.java:393) ~[PlugManX.jar:?]
        at com.rylinaux.plugman.command.ReloadCommand.execute(ReloadCommand.java:122) ~[PlugManX.jar:?]
        at com.rylinaux.plugman.PlugManCommandHandler.onCommand(PlugManCommandHandler.java:95) ~[PlugManX.jar:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[pufferfish-api-1.18.2-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:159) ~[pufferfish-api-1.18.2-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.craftbukkit.v1_18_R2.CraftServer.dispatchCommand(CraftServer.java:906) ~[pufferfish-1.18.2.jar:git-Pufferfish-66]
        at org.bukkit.craftbukkit.v1_18_R2.CraftServer.dispatchServerCommand(CraftServer.java:869) ~[pufferfish-1.18.2.jar:git-Pufferfish-66]
        at net.minecraft.server.dedicated.DedicatedServer.handleConsoleInputs(DedicatedServer.java:513) ~[pufferfish-1.18.2.jar:git-Pufferfish-66]
        at net.minecraft.server.dedicated.DedicatedServer.tickChildren(DedicatedServer.java:487) ~[pufferfish-1.18.2.jar:git-Pufferfish-66]
        at net.minecraft.server.MinecraftServer.tickServer(MinecraftServer.java:1457) ~[pufferfish-1.18.2.jar:git-Pufferfish-66]
        at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1227) ~[pufferfish-1.18.2.jar:git-Pufferfish-66]
        at net.minecraft.server.MinecraftServer.lambda$spin$1(MinecraftServer.java:317) ~[pufferfish-1.18.2.jar:git-Pufferfish-66]
        at java.lang.Thread.run(Thread.java:833) ~[?:?]
Caused by: java.lang.IllegalArgumentException: 'RedisURI' is already in use
        at io.netty.util.ConstantPool.createOrThrow(ConstantPool.java:108) ~[netty-all-4.1.68.Final.jar:4.1.68.Final]
        at io.netty.util.ConstantPool.newInstance(ConstantPool.java:90) ~[netty-all-4.1.68.Final.jar:4.1.68.Final]
        at io.netty.util.AttributeKey.newInstance(AttributeKey.java:55) ~[netty-all-4.1.68.Final.jar:4.1.68.Final]
        at dev.goliath.libs.lettuce.core.ConnectionBuilder.<clinit>(ConnectionBuilder.java:62) ~[Core-1.0.1.jar:?]
        ... 23 more</summary>
// your stack trace here;
public class RedisMessenger {

    private final List<Thread> pubsubs = new LinkedList<>();
    private String host;
    private int port;
    private String password;
    private RedisClient redisClient;
    StatefulRedisConnection<byte[],byte[]> sender;
    private final byte[] data = "Goliath".getBytes(StandardCharsets.UTF_8);

    public RedisMessenger(String host, int port, String password){
        this.host = host;
        this.port = port;
        this.password = password;
        redisClient = RedisClient.create(RedisURI.builder().withHost(host).withPort(port)
                .withPassword(password).withDatabase(0)
                .withTimeout(Duration.ofSeconds(30000)).build());
        sender = redisClient.connect(new ByteArrayCodec());
    }

    public static byte[] compress(byte[] text){
        return Zstd.compress(text);
    }

    public void publishData(byte[] channel,byte[] message){
        Executor.submit(()-> sender.sync().publish(channel,compress(message)));
    }

    public void registerPubSub(RedisPubSubAdapter<byte[],byte[]> sub, byte[] ... names){
        Thread thread = new Thread(()-> {
            StatefulRedisPubSubConnection<byte[],byte[]> connection = redisClient.connectPubSub(new ByteArrayCodec());
            connection.addListener(sub);
            RedisPubSubAsyncCommands<byte[],byte[]> pubSubCommands = connection.async();
            pubSubCommands.subscribe(names);
            connection.close();
        });
        pubsubs.add(thread);
        thread.setDaemon(true);
        thread.start();
    }

    public void stop(){

        try {
            redisClient.shutdown();
        } catch (Exception ignored){
            ignored.printStackTrace();
        }


        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        for (Thread thread : pubsubs) {
            try {
                thread.interrupt();
            } catch (Exception ignored){ }
            try {
                thread.stop();
            } catch (Exception ignored){ }
        }
        Executor.executor.getPoolExecutor().shutdown();
    }

    public void publishMessage(String message){
        // wrap send message here.

        Bukkit.broadcastMessage(ColorUtil.translate(message));

        DeathMessagePacket deathMessagePacket = new DeathMessagePacket();
        deathMessagePacket.setMessage(message);
        publishData(data,deathMessagePacket.write());

        //Executor.submit(()-> sender.sync().publish(data,compress(message.getBytes(StandardCharsets.UTF_8))));
    }

}

Expected behavior/code

The expected behavior would be to be able to restart the application without that error, what am I doing wrong?

Environment

  • Lettuce version(s): 6.1.8.RELEASE
  • Redis version: 7.0

Possible Solution

Additional context

@mp911de
Copy link
Collaborator

mp911de commented Jul 1, 2022

It seems that dev.goliath.libs.lettuce.core.ConnectionBuilder is attempting to register a netty channel attribute that is already in use. Please contact the author of dev.goliath.libs.lettuce.core.ConnectionBuilder to get this fixed. We only maintain io.lettuce.core packages in this project.

@mp911de mp911de closed this as not planned Won't fix, can't repro, duplicate, stale Jul 1, 2022
@mp911de mp911de added the for: external-project For an external project and not something we can fix label Jul 1, 2022
@rexlManu
Copy link

rexlManu commented Nov 4, 2022

Hey, I don't like to dig in old issues but this issue is still unfixed.

In your comment:

It seems that dev.goliath.libs.lettuce.core.ConnectionBuilder is attempting to register a netty channel attribute that is already in use. Please contact the author of dev.goliath.libs.lettuce.core.ConnectionBuilder to get this fixed. We only maintain io.lettuce.core packages in this project.

You oversee that it's just relocated.
So yea the issue exist in the ConnectionBuilder in the package io.lettuce.core.

@PedroMPagani
Copy link
Author

It seems that dev.goliath.libs.lettuce.core.ConnectionBuilder is attempting to register a netty channel attribute that is already in use. Please contact the author of dev.goliath.libs.lettuce.core.ConnectionBuilder to get this fixed. We only maintain io.lettuce.core packages in this project.

Hey, I just saw this message sorry, this issue is in the lettuce package, it's renamed differently just due to shading the dependency, I had to reallocate exactly for the same reason.

@rexlManu
Copy link

rexlManu commented Nov 4, 2022

It seems that dev.goliath.libs.lettuce.core.ConnectionBuilder is attempting to register a netty channel attribute that is already in use. Please contact the author of dev.goliath.libs.lettuce.core.ConnectionBuilder to get this fixed. We only maintain io.lettuce.core packages in this project.

Hey, I just saw this message sorry, this issue is in the lettuce package, it's renamed differently just due to shading the dependency, I had to reallocate exactly for the same reason.

Yea I still have the issue if you reload the server with redisuri even with relocating. If you find a way to work around, I would be glad to know that.

@PedroMPagani
Copy link
Author

It seems that dev.goliath.libs.lettuce.core.ConnectionBuilder is attempting to register a netty channel attribute that is already in use. Please contact the author of dev.goliath.libs.lettuce.core.ConnectionBuilder to get this fixed. We only maintain io.lettuce.core packages in this project.

Hey, I just saw this message sorry, this issue is in the lettuce package, it's renamed differently just due to shading the dependency, I had to reallocate exactly for the same reason.

Yea I still have the issue if you reload the server with redisuri even with relocating. If you find a way to work around, I would be glad to know that.

Hey, I have not found a fix for it, didn't really dig much on it, this issue is mainly for Minecraft developers else other applications, since they would usually be turned off and turned back on, while we reload classes.

@Emibergo02
Copy link
Contributor

Emibergo02 commented Nov 21, 2022

still not fixed.
here is some more stacktrace without relocating anything

[01:01:27 ERROR]: Error occurred while enabling RedisEconomy v3.0-SNAPSHOT (Is it up to date?)
java.lang.ExceptionInInitializerError: null
        at io.lettuce.core.RedisClient.connectStatefulAsync(RedisClient.java:310) ~[?:?]
        at io.lettuce.core.RedisClient.connectStandaloneAsync(RedisClient.java:287) ~[?:?]
        at io.lettuce.core.RedisClient.connect(RedisClient.java:216) ~[?:?]
        at io.lettuce.core.RedisClient.connect(RedisClient.java:201) ~[?:?]
        at dev.unnm3d.rediseconomy.redis.RedisManager.getConnection(RedisManager.java:16) ~[RedisEconomy-3.0-SNAPSHOT.jar:?]
        at dev.unnm3d.rediseconomy.redis.RedisManager.isConnected(RedisManager.java:30) ~[RedisEconomy-3.0-SNAPSHOT.jar:?]
        at dev.unnm3d.rediseconomy.RedisEconomyPlugin.setupRedis(RedisEconomyPlugin.java:136) ~[RedisEconomy-3.0-SNAPSHOT.jar:?]
        at dev.unnm3d.rediseconomy.RedisEconomyPlugin.onEnable(RedisEconomyPlugin.java:50) ~[RedisEconomy-3.0-SNAPSHOT.jar:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264) ~[purpur-api-1.19.2-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:370) ~[purpur-api-1.19.2-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:548) ~[purpur-api-1.19.2-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.craftbukkit.v1_19_R1.CraftServer.enablePlugin(CraftServer.java:596) ~[purpur-1.19.2.jar:git-Purpur-1809]
        at org.bukkit.craftbukkit.v1_19_R1.CraftServer.enablePlugins(CraftServer.java:510) ~[purpur-1.19.2.jar:git-Purpur-1809]
        at net.minecraft.server.MinecraftServer.loadWorld0(MinecraftServer.java:641) ~[purpur-1.19.2.jar:git-Purpur-1809]
        at net.minecraft.server.MinecraftServer.loadLevel(MinecraftServer.java:427) ~[purpur-1.19.2.jar:git-Purpur-1809]
        at net.minecraft.server.dedicated.DedicatedServer.initServer(DedicatedServer.java:343) ~[purpur-1.19.2.jar:git-Purpur-1809]
        at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1116) ~[purpur-1.19.2.jar:git-Purpur-1809]
        at net.minecraft.server.MinecraftServer.lambda$spin$1(MinecraftServer.java:310) ~[purpur-1.19.2.jar:git-Purpur-1809]
        at java.lang.Thread.run(Thread.java:833) ~[?:?]
Caused by: java.lang.IllegalArgumentException: 'RedisURI' is already in use
        at io.netty.util.ConstantPool.createOrThrow(ConstantPool.java:108) ~[netty-common-4.1.77.Final.jar:4.1.77.Final]
        at io.netty.util.ConstantPool.newInstance(ConstantPool.java:90) ~[netty-common-4.1.77.Final.jar:4.1.77.Final]
        at io.netty.util.AttributeKey.newInstance(AttributeKey.java:55) ~[netty-common-4.1.77.Final.jar:4.1.77.Final]
        at io.lettuce.core.ConnectionBuilder.<clinit>(ConnectionBuilder.java:62) ~[?:?]
        ... 19 more

@Emibergo02
Copy link
Contributor

@Emibergo02
Copy link
Contributor

Emibergo02 commented Nov 22, 2022

i think that AttributeKey.newInstance("RedisURI"); should be AttributeKey.valueOf("RedisURI"); here
so it calls getOrCreate instead of createOrThrow

@rexlManu
Copy link

Hey, coming back to that. That was my way of fixing it but I never pr'ed it. Maybe a maintainer should answer that better.

@Emibergo02
Copy link
Contributor

yep. i tested it. fixed in #2260

mp911de pushed a commit that referenced this issue Nov 23, 2022
…2111 #2260

Changed the method used to make sure that it calls getOrCreate instead of createOrThrow
mp911de pushed a commit that referenced this issue Nov 23, 2022
…2111 #2260

Changed the method used to make sure that it calls getOrCreate instead of createOrThrow
Emibergo02 added a commit to Emibergo02/RedisEconomy that referenced this issue Nov 23, 2022
@mp911de mp911de changed the title Shutdown issue Proper creation of AttributeKey Dec 6, 2022
@mp911de mp911de added type: bug A general bug and removed for: external-project For an external project and not something we can fix labels Dec 6, 2022
@mp911de mp911de added this to the 6.2.2.RELEASE milestone Dec 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants