[vlc-devel] [PATCH] http: fix data-race
Thomas Guillem
thomas at gllm.fr
Thu Oct 18 16:01:28 CEST 2018
Fix the following tsan report:
~/work/git/vlc/build-tsan/modules $ ./h2conn_test
==================
WARNING: ThreadSanitizer: data race (pid=20689)
Write of size 1 at 0x7b20000000a5 by thread T4:
#0 vlc_h2_stream_reset ../../modules/access/http/h2conn.c:206 (h2conn_test+0x8a6a)
#1 vlc_h2_recv_thread ../../modules/access/http/h2conn.c:676 (h2conn_test+0x9029)
#2 <null> <null> (libtsan.so.0+0x29b4d)
Previous read of size 1 at 0x7b20000000a5 by main thread (mutexes: write M12):
#0 vlc_h2_stream_wait ../../modules/access/http/h2conn.c:246 (h2conn_test+0x917d)
#1 vlc_http_stream_read_headers ../../modules/access/http/message.h:360 (h2conn_test+0x40ff)
#2 main ../../modules/access/http/h2conn_test.c:283 (h2conn_test+0x40ff)
Location is heap block of size 128 at 0x7b2000000080 allocated by main thread:
#0 malloc <null> (libtsan.so.0+0x2b1b3)
#1 vlc_h2_stream_open ../../modules/access/http/h2conn.c:404 (h2conn_test+0x9afc)
#2 vlc_http_stream_open ../../modules/access/http/conn.h:49 (h2conn_test+0x3be8)
#3 stream_open ../../modules/access/http/h2conn_test.c:124 (h2conn_test+0x3be8)
#4 main ../../modules/access/http/h2conn_test.c:280 (h2conn_test+0x40c3)
Mutex M12 (0x7b1800000030) created at:
#0 pthread_mutex_init <null> (libtsan.so.0+0x2c5bd)
#1 vlc_mutex_init ../../src/posix/thread.c:116 (libvlccore.so.9+0xeadba)
#2 vlc_h2_conn_create ../../modules/access/http/h2conn.c:736 (h2conn_test+0xa10e)
#3 conn_create ../../modules/access/http/h2conn_test.c:100 (h2conn_test+0x393c)
#4 main ../../modules/access/http/h2conn_test.c:165 (h2conn_test+0x3cd1)
Thread T4 (tid=20707, running) created by main thread at:
#0 pthread_create <null> (libtsan.so.0+0x2be2b)
#1 vlc_clone_attr ../../src/posix/thread.c:431 (libvlccore.so.9+0xeabcf)
#2 vlc_clone ../../src/posix/thread.c:443 (libvlccore.so.9+0xeb11b)
#3 vlc_h2_conn_create ../../modules/access/http/h2conn.c:739 (h2conn_test+0xa13a)
#4 conn_create ../../modules/access/http/h2conn_test.c:100 (h2conn_test+0x393c)
#5 main ../../modules/access/http/h2conn_test.c:165 (h2conn_test+0x3cd1)
The good news is that there is only 4 remaining tests to fix with tsan.
---
modules/access/http/h2conn.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/modules/access/http/h2conn.c b/modules/access/http/h2conn.c
index 0cbef910a1..4aa96c16f0 100644
--- a/modules/access/http/h2conn.c
+++ b/modules/access/http/h2conn.c
@@ -672,8 +672,10 @@ static void *vlc_h2_recv_thread(void *data)
vlc_h2_parse_destroy(parser);
fail:
/* Terminate any remaining stream */
+ vlc_mutex_lock(&conn->lock);
for (struct vlc_h2_stream *s = conn->streams; s != NULL; s = s->older)
vlc_h2_stream_reset(s, VLC_H2_CANCEL);
+ vlc_mutex_unlock(&conn->lock);
return NULL;
}
--
2.19.1
More information about the vlc-devel
mailing list