(v3.0.3) THashSet NoSuchElementException when call addAll()

Issue #52 invalid
Liang Shen created an issue

After upgrade JDK1.8 (build 1.8.0_40-ea-b20), time to time, I will encounter this exception in servlet. It is very strange. After study the value, I find the THashSet 'size' is wrong. in my below case, the actual size is 5, while the variable record it as 6. That is why when addAll(), I encounter this exception.

In the last screen, you can tell, only 5 items are in the set.

I am pretty sure I am using the single thread although my servlet is multiple thread environment. Because I am using the Disruptor ring buffer handler. (https://github.com/LMAX-Exchange/disruptor)

Screen Shot 2015-01-20 at 2.47.26 pm.png

Screen Shot 2015-01-20 at 2.48.05 pm.png

Screen Shot 2015-01-20 at 2.50.55 pm.png

Screen Shot 2015-01-20 at 2.49.30 pm.png

Comments (9)

  1. Rob Eden

    I've never heard of this happening without being a threading issue. If you think otherwise, we'll need some more debugging info and possibly a test case.

  2. Liang Shen reporter

    I find a similar report in the source forge. Anyway, I am also very confused on this issue. My other modules (all are multiple thread) which is also using the same library has no issue. So I suspect it may be caused by the atmosphere (comet) connection. Just would like to log this issue here. In case I find out the root cause on this issue, I will post the reason here. Thanks

  3. Rob Eden

    You could wrap the collection in a synchronization wrapper (TCollections.synchronizedSet(...)) and see if that helps.

    How reliable is the error? Would you know it's fixed/avoided if it doesn't happen in -say- a week?

  4. Rob Eden

    And yes, there have definitely been similar reports. It gets reported quite often. But like I said, it always turns out to be a threading issue. People are often not aware that collections can be accessed from multiple threads when they actually are.

    I'm not going to say that it's impossible that it's a bug in Trove, but I'll take some convincing. ;-)

  5. Liang Shen reporter

    my modules have run for 1 year (7X24 hours) without any issue. :( only recently after I upgrade Java to JDK1.8 & atmosphere to the latest version. Then only the servlet got problem in my development environement. and if my observation is correct, it seems the exception always happen after atmosphere complains the connection is not close properly (which is quite common for unstable mobile device connection). Besides this error, I find another error report from Trove, atmosphere resource class hash code isn't compliance! (hash code & equal() doesn't follow JDK spec). But that error only happen twice then gone.

    I need some time to observe this error. If really can't solve it out, I have to follow you suggestion to add sync. Thanks a lot.

  6. Liang Shen reporter

    I may find out the reason. YES, IT IS NOTHING TO DO WITH TROVE!. The atmosphere library class "AtmosphereResourceImpl" only override the 'equal' with system default hashCode()!!!

    No wonder I only encounter this issue in this servlet. Thanks.

  7. Rob Eden

    Thanks for the update. For now I'm going to mark this resolved. If you come to believe it's Trove again, feel free to reopen.

  8. Log in to comment