Skip to content

fixes for two more TSAN races - #651

Merged
michalvasko merged 2 commits into
CESNET:develfrom
jktjkt:cesnet/fix-tsan
Oct 19, 2026
Merged

michalvasko merged 2 commits into
CESNET:develfrom
jktjkt:cesnet/fix-tsan

Conversation

@jktjkt

@jktjkt jktjkt commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

I was checking whether commit ac86ff1 fixed all problems that I hit in #648, and there's a couple more.

jktjkt and others added 2 commits October 16, 2026 18:06
The client thread logs while setting up its call-home bind, so the log
callback can read the expected message while the server thread is still
writing it:

    WARNING: ThreadSanitizer: data race (pid=3869790)
      Read of size 8 at 0x555556aa75b0 by thread T7 (mutexes: write M0):
        #0 strstr <null>
        CESNET#1 test_msg_callback tests/test_ch.c:55:9
        CESNET#2 nc_log_vprintf src/log.c:134:9
        CESNET#3 nc_log_printf src/log.c:152:5
        CESNET#4 nc_sock_bind_inet src/session_server.c
        CESNET#5 nc_sock_listen_inet src/session_server.c:563:9
        CESNET#6 nc_client_ch_add_bind_listen src/session_client.c:1765:12
        CESNET#7 nc_client_ssh_ch_add_bind_listen src/session_client_ssh.c:1268:12
        CESNET#8 client_thread_delete_while_session tests/test_ch.c:504:11

      Previous write of size 8 at 0x555556aa75b0 by thread T8:
        #0 __tsan_memcpy <null>
        CESNET#1 server_thread_delete_while_session tests/test_ch.c:447:5

      Location is global 'expected' of size 512 at 0x555556aa75b0

Reset both the buffer and the expected message under the lock.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The print callback may be changed while other threads are logging, as
test_ch does when the server thread installs its callback while the
client thread is already setting up its call-home bind:

    WARNING: ThreadSanitizer: data race (pid=3869790)
      Read of size 8 at 0x555556aa6f78 by thread T7:
        #0 nc_log_vprintf src/log.c:133:9
        CESNET#1 nc_log_printf src/log.c:152:5
        CESNET#2 nc_sock_bind_inet src/session_server.c
        CESNET#3 nc_sock_listen_inet src/session_server.c:563:9
        CESNET#4 nc_client_ch_add_bind_listen src/session_client.c:1765:12
        CESNET#5 nc_client_ssh_ch_add_bind_listen src/session_client_ssh.c:1268:12
        CESNET#6 client_thread_delete_while_session tests/test_ch.c:504:11

      Previous write of size 8 at 0x555556aa6f78 by thread T8:
        #0 nc_set_print_clb_session src/log.c:159:15
        CESNET#1 server_thread_delete_while_session tests/test_ch.c:445:5

      Location is global 'print_clb' of size 8 at 0x555556aa6f78

Store it as an atomic pointer, just like the verbosity level.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@michalvasko
michalvasko merged commit b96ff7f into CESNET:devel Oct 19, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants