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.

PromiseTask.isCancelled performs an unsynchronized read

See original GitHub issue

In #9744 @njhill changed PromiseTask.isCancelled to:

https://github.com/netty/netty/blob/fcf55fcf718af1e4cae85eb86cdb679094186aed/common/src/main/java/io/netty/util/concurrent/PromiseTask.java#L180-L182

But task is just a plain field:

https://github.com/netty/netty/blob/fcf55fcf718af1e4cae85eb86cdb679094186aed/common/src/main/java/io/netty/util/concurrent/PromiseTask.java#L65

A race detector is noticing this unsynchronized read/write.

The write is occurring in clearTaskAfterCompletion(), which does mention the potential for a write race, which does seem likely to be minor:

https://github.com/netty/netty/blob/fcf55fcf718af1e4cae85eb86cdb679094186aed/common/src/main/java/io/netty/util/concurrent/PromiseTask.java#L114-L123

I’ve not spent too much time looking at it, but it is unclear to me why task == CANCELLED is even checked in isCancelled(); it seems like DefaultPromise.isCancelled() should be enough. It sort of seems like the semantics of isCancelled() are being changed to be more of a isDone(). But I don’t think I understand the code enough to know how serious this race is.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
ejona86commented, Feb 12, 2020

There used to be more failures in Netty, but many of them have been fixed. I did find a whitelist and it appears the only Netty race whitelisted is from io.netty.util.Recycler$WeakOrderQueue.transfer (not saying such a race still exists). But I do see a reasonable number of races ignored for the java standard library. That might be to just allow the tool to be used; stop new issues from being introduced and clean up preexisting issues over time.

In any case, if we don’t get much performance benefit it is probably best to remove the optimization. If we can show the benefit then we can try to get on the whitelist.

0reactions
normanmaurercommented, Feb 27, 2020
Read more comments on GitHub >

github_iconTop Results From Across the Web

PromiseTask.isCancelled performs an unsynchronized read ...
Motivation: PromiseTask.isCancelled performs an unsynchronized read and so may trigger race-detectors. As this was just done for a small optimization which ...
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