RFR: 8351601: [JMH] test UnixSocketChannelReadWrite failed for 2 threads config
Volkan Yazici
vyazici at openjdk.org
Mon Mar 24 08:46:17 UTC 2025
On Fri, 21 Mar 2025 16:07:19 GMT, Michael McMahon <michaelm at openjdk.org> wrote:
> Seems like the only explanation for why that is happening is someone cleaning out /tmp while the test is running
@Michael-Mc-Mahon No, the reason for the failure is multiple threads creating a Unix socket in the very same `tempDir`, and then trying to delete the `tempDir`. See the following execution flow involving multiple threads:
1. `tempDir` is statically assigned during class initialization (say `/tmp/readWriteTest2414375588689416060`)
2. `Thread1` runs `beforeRun()`, which creates the Unix socket `/tmp/readWriteTest2414375588689416060/1`
3. `Thread2` runs `beforeRun()`, which creates the Unix socket `/tmp/readWriteTest2414375588689416060/2`
4. Both `Thread1` and `Thread2` runs `afterRun()` in parallel
5. `Thread1` runs `Files.delete(/tmp/readWriteTest2414375588689416060/1)` and succeeds
6. `Thread2` runs `Files.delete(/tmp/readWriteTest2414375588689416060/2)` and succeeds
7. `Thread1` runs `Files.delete(/tmp/readWriteTest2414375588689416060)` and succeeds (since both `/1` and `/2` socket files are removed above, and, hence, the directory is empty)
8. `Thread2` runs `Files.delete(/tmp/readWriteTest2414375588689416060)` and fails, since the directory has already been deleted above
Ideally, `tempDir` deletion should be performed by a single thread. But replacing `Files::delete` with `Files::deleteIfExists` also does the job, at a lower cost.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/24126#issuecomment-2747320538
More information about the net-dev
mailing list