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

[Bug] Calling a value is not thread safe (return another value) #268

Closed
Amerousful opened this issue Jun 6, 2020 · 10 comments
Closed

[Bug] Calling a value is not thread safe (return another value) #268

Amerousful opened this issue Jun 6, 2020 · 10 comments

Comments

@Amerousful
Copy link

Amerousful commented Jun 6, 2020

I noticed that when calling values ​​from different threads, it can returns values ​​from other methods. The wrong method is invoked somehow. Bug reproduced on version 1.0.11
I tried 1.0.8 - 1.0.10 and all ok.

src/test/resources/config.properties

firstName=Pasha
lastName=Bairov

import org.aeonbits.owner.Config;

@Config.Sources({"file:src/test/resources/config.properties"})
public interface MyConfig extends Config {

    @Key("firstName")
    String firstName();

    @Key("lastName")
    String lastName();
}

public static void main(String[] args) {
        MyConfig cfg = ConfigFactory.create(MyConfig.class);


        new Thread(() -> {
            for (int i = 0; i < 1000; i++) {
                String name = cfg.firstName();

                if (!name.equals("Pasha")) {
                    System.out.println("name " + name);
                }
            }
        }).start();

        new Thread(() -> {
            for (int i = 0; i < 1000; i++) {
                cfg.lastName();
            }
        }).start();
    }

I executed it 1000 times and here it stdout:

name Bairov
name Bairov
name Bairov
name Bairov
name Bairov

I can provide any necessary information for debugging.

@lviggiano
Copy link
Collaborator

lviggiano commented Jun 6, 2020

This is ugly. Thanks for the bug report.

I really need to take back my hands on this project.

@lviggiano
Copy link
Collaborator

There are few patched added from 1.0.10 to 1.0.11, so what we can do is to repeat your test for every code change, and verify what is the patch that introduced the bug, then find the fix.
If you happen to find more, please let me know.
I'll try to get this fixed.

@lviggiano
Copy link
Collaborator

lviggiano commented Jun 6, 2020

it looks like the problem has been introduced by commit 1acb314

@lviggiano
Copy link
Collaborator

which in turn, is the merge of #255 #254

@lviggiano
Copy link
Collaborator

I released 1.0.12, this should fix the issue. Let me know.

@lviggiano
Copy link
Collaborator

thank you for the unit test, really appreciated you took the time to produce a test case to reproduce the issue. I wrote a unit test inspired to your code. So this issue hopefully will not show up again.

@Amerousful
Copy link
Author

Amerousful commented Jun 8, 2020

I was very glad to help!
Thanks for the quick response and fix. I will wait the new version.

I wanted to write the test by myself but you was faster than me :)

@lviggiano
Copy link
Collaborator

@Amerousful It's already released. 1.0.12, try that out and let me know.

@Amerousful
Copy link
Author

@lviggiano Yes, it works fine! Thanks!

@lviggiano
Copy link
Collaborator

@Amerousful Glad it helped. Thank you for your valuable time in helping.

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