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.

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

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10

github_iconTop GitHub Comments

1reaction
lviggianocommented, Jun 8, 2020

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

1reaction
lviggianocommented, Jun 7, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Bug] Calling a value is not thread safe (return another value)
I noticed that when calling values ​​from different threads, it can returns values ​​from other methods. The wrong method is invoked somehow ...
Read more >
Is it thread safe to read a form controls value (but not change it ...
Question 2: I have a second thread that needs to update form control values so I Invoke/BeginInvoke to update those values. Well this...
Read more >
How to make thread-safe calls to controls - Windows Forms .NET
Learn how to implement multithreading in your app by calling cross-thread controls in a thread-safe way. If you encounter the 'cross-thread ...
Read more >
inout paremeter and thread safety | Apple Developer Forums
When I call this func from another thread, I get random crashes (BAD_ACCESS). I understand it is not safe to pass address in...
Read more >
Writing reentrant and threadsafe code - IBM
A thread may read an error code corresponding to an error caused by another thread. In AIX®, each thread has its own errno...
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