Re: [PATCH bpf-next v1] selftests/bpf: Fix stdout race condition in traffic monitor

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2/13/25 4:19 PM, Amery Hung wrote:
On Thu, Feb 13, 2025 at 3:55 PM Martin KaFai Lau <martin.lau@xxxxxxxxx> wrote:

On 2/13/25 3:32 PM, Amery Hung wrote:
Fix a race condition between the main test_progs thread and the traffic
monitoring thread. The traffic monitor thread tries to print a line
using multiple printf and use flockfile() to prevent the line from being
torn apart. Meanwhile, the main thread doing io redirection can reassign
or close stdout when going through tests. A deadlock as shown below can
happen.

         main                      traffic_monitor_thread
         ====                      ======================
                                   show_transport()
                                   -> flockfile(stdout)

stdio_hijack_init()
-> stdout = open_memstream(log_buf, log_cnt);
     ...
     env.subtest_state->stdout_saved = stdout;

                                      ...
                                      funlockfile(stdout)
stdio_restore_cleanup()
-> fclose(env.subtest_state->stdout_saved);

Great debugging.

Does it mean that the main thread will start the next test before the
traffic_monitor_thread has finished? Meaning the traffic_monitor_stop() does not
wait for the traffic_monitor_thread somehow?

That part I think is fine. The race condition here happen between
subtests within the same "netns_new" scope. For example,
test_flow_dissector_skb_less_direct_attach.

Got it. Thanks for the fix. Applied.





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux