RFR: 8316337: (bf) Concurrency issue in DirectByteBuffer.Deallocator [v3]

Alan Bateman alanb at openjdk.org
Mon Sep 18 14:57:40 UTC 2023


On Mon, 18 Sep 2023 14:28:02 GMT, Chen Liang <liach at openjdk.org> wrote:

> Shouldn't this be an atomic compareAndSet instead? Thread A can read deallocated and pause before the field write, then thread B read deallocated, continue to set the field. There will be a double free when thread A resumes.

Deallocator is the cleaner action so it should only ever be run once by the cleaner thread. There is a back door via Unsafe.invokeCleaner for freeing a buffer potentially in use but the cleaner action should still only be invoked once.  The "Paranoia" comment and guarding against being called again may date back to the older cleaner code, requires a bit of digging to see if (and the flag) can be removed.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/15784#discussion_r1328857155


More information about the nio-dev mailing list