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

Java runtime reference #125

Open
delawr0190 opened this issue Sep 22, 2023 · 2 comments
Open

Java runtime reference #125

delawr0190 opened this issue Sep 22, 2023 · 2 comments

Comments

@delawr0190
Copy link

delawr0190 commented Sep 22, 2023

Assuming I'm using the java library correctly, I believe there's either a missing Runtime reference hold or the documentation may need to be updated to reflect how Runtime should be treated.

In my multi-threaded use of the library:

        final RuntimeConfig runtimeConfig =
                new RuntimeConfig()
                        .withNumCoreThreads(ushort(4));
        final Runtime runtime = new Runtime(runtimeConfig);
        this.channel =
                ClientChannel.createTcp(
                        runtime,
                        ip,
                        ushort(port),
                        ushort(1),
                        new RetryStrategy(),
                        DecodeLevel.nothing(),
                        state -> LOG.warn("State change: {}", state));
        this.channel.enable();

A separate scheduled executor periodically initiates reads from the channel.

With nothing holding the runtime reference, the gc seems to prune it, calling finalize(), which shuts down the Runtime and "SHUTDOWN" exceptions start to get thrown.

To fix this, holding the reference to Runtime on the class keeps the gc from deleting it, which keeps things going.

Couldn't find reference to this anywhere, so wanted to share. Unsure if intended or not.

@jadamcrain
Copy link
Member

Hi @delawr0190. This is the expected behavior, although I think we should have an explicit warning about holding onto a reference to runtime until you're done here:

https://docs.stepfunc.io/rodbus/1.3.1/guide/docs/api/runtime#examples

We kind of hint about how the garbage collection interacts with this in the shutdown section, but I think calling it out explicitly for Java/C# in the section above would be better.

https://docs.stepfunc.io/rodbus/1.3.1/guide/docs/api/runtime#shutdown

@jadamcrain
Copy link
Member

Leaving this open until the next release so we can update docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants