Expression icon indicating copy to clipboard operation
Expression copied to clipboard

Fishy locking in CancellationSource

Open ytimenkov opened this issue 1 year ago • 1 comments

Describe the bug Usage of _lock in https://github.com/cognitedata/Expression/blob/main/expression/system/cancellation.py doesn't look correct.

I was looking through files and got puzzled by how CancellationTokenSource.dispose() is implemented.

Apparently it tries to read _is_disposed under the lock but on the next like assigns it without lock. It also calls listeners without lock.

On the other hand register_internal seems to do the opposite: it reads _is_disposed without lock and accesses _listeners inside a critical section.

To be strict all access to variables should be protected and protected consistently. E.g. if it's dangerous to call a callback under the lock - a copy (slice) of _listeners could be made (in the same critical section with checking for _is_disposed).

ytimenkov avatar Aug 02 '22 06:08 ytimenkov

@ytimenkov Thanks for posting this issue. It indeed looks like a bug.

dbrattli avatar Aug 03 '22 12:08 dbrattli