This is an archive of the discontinued LLVM Phabricator instance.

[tsan] Keep thread/stack for closed FD
ClosedPublic

Authored by vitalybuka on Aug 17 2022, 1:47 PM.

Diff Detail

Event Timeline

vitalybuka created this revision.Aug 17 2022, 1:47 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 17 2022, 1:47 PM
Herald added a subscriber: Enna1. · View Herald Transcript
vitalybuka requested review of this revision.Aug 17 2022, 1:47 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 17 2022, 1:47 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript
dvyukov accepted this revision.Aug 17 2022, 11:50 PM
dvyukov added inline comments.
compiler-rt/test/tsan/fd_location_closed.cpp
9

This barrier won't really ensure any particular ordering of the racing events, right?
Such tests w/o ordering used to be flaky. We generally create only 2 thread and fix the needed order of events with the barrier.

This revision is now accepted and ready to land.Aug 17 2022, 11:50 PM

update the test

compiler-rt/test/tsan/fd_location_closed.cpp
9

We need race between read and close, and then, when we start reporting, another close on the read thread must destroy the fd
If I put barrier like this it detects for me every time.
%deflake also should help

vitalybuka added inline comments.Aug 18 2022, 12:48 AM
compiler-rt/test/tsan/fd_location_closed.cpp
9
WARNING: ThreadSanitizer: data race (pid=4113552)
  Write of size 8 at 0x7bb000000060 by thread T2:
    #0 close compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp:1769:3 (fd_location_closed.cpp.tmp+0x58665)
    #1 Thread(void*) compiler-rt/test/tsan/fd_location_closed.cpp:11:3 (fd_location_closed.cpp.tmp+0xd59a5)

  Previous read of size 8 at 0x7bb000000060 by thread T1:
    #0 read compiler-rt/lib/tsan/rtl/../../sanitizer_common/sanitizer_common_interceptors.inc:1091:3 (fd_location_closed.cpp.tmp+0x5e684)
    #1 Thread(void*) compiler-rt/test/tsan/fd_location_closed.cpp:9:3 (fd_location_closed.cpp.tmp+0xd5992)

  Location is file descriptor 3 destroyed by thread T1 at:
    #0 close compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp:1769:3 (fd_location_closed.cpp.tmp+0x58665)
    #1 Thread(void*) compiler-rt/test/tsan/fd_location_closed.cpp:11:3 (fd_location_closed.cpp.tmp+0xd59a5)

  Thread T2 (tid=4113555, running) created by main thread at:
    #0 pthread_create compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp:1022:3 (fd_location_closed.cpp.tmp+0x537bd)
    #1 main compiler-rt/test/tsan/fd_location_closed.cpp:20:3 (fd_location_closed.cpp.tmp+0xd5a37)

  Thread T1 (tid=4113554, finished) created by main thread at:
    #0 pthread_create compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp:1022:3 (fd_location_closed.cpp.tmp+0x537bd)
    #1 main compiler-rt/test/tsan/fd_location_closed.cpp:19:3 (fd_location_closed.cpp.tmp+0xd5a22)
dvyukov accepted this revision.Aug 18 2022, 12:54 AM
This revision was automatically updated to reflect the committed changes.

I see @dblaikie already reverted this but in case you want some output to look at here's one of Linaro's failing builds: https://lab.llvm.org/buildbot/#/builders/179/builds/4279