Threading bug: state of 'alive' variable not guaranteed to be synchronized across threads.

Issue #1 new
David Bullock created an issue

In https://bitbucket.org/mrdon/enchanter/src/27d274b22efdd11d781fb506ed46784c448e8f52/core/src/main/java/org/twdata/enchanter/impl/DefaultStreamConnection.java?at=master

..,. you update/read the 'alive' field from different threads (main thread, and timer thread), but without any synchronization. You should either use a 'synchronized' block (locking on a 'final Object lock;') or you should use a java.util.concurrent.ReentrantLock

The point of doing this is so that when the 'alive' field is set to 'false' by the timeoutThread, the main thread will eventually see that value in the guard-condition of the 'while' loop. Unpredictable behaviour may result if this is not done.

However, feel free to not fix this bug since I'm happily using Expect-for-Java which - although it provides no bindings for scripting languages - does a good job with managing the control-flow, and supports regex patterns for matching. I just mention it in case anyone gets odd behaviour with timeouts.

Comments (0)

  1. Log in to comment