scrcpy/app/src
Romain Vimont c996a6d462 Fix socket close race condition
The server needs to interrupt the sockets on stop, but it must not close
them while other threads may attempt to read from or write to them.

In particular, the video_socket is read by the stream thread, and the
control_socket is written by the controller and read by receiver.

Therefore, close the socket only on sc_server_destroy(), which is called
after all other threads are joined.

Reported by TSAN on close:

    WARNING: ThreadSanitizer: data race (pid=3287612)
      Write of size 8 at 0x7ba000000080 by thread T1:
        #0 close ../../../../src/libsanitizer/tsan/tsan_interceptors_posix.cpp:1690 (libtsan.so.0+0x359d8)
        #1 net_close ../app/src/util/net.c:280 (scrcpy+0x23643)
        #2 run_server ../app/src/server.c:772 (scrcpy+0x20047)
        #3 <null> <null> (libSDL2-2.0.so.0+0x905a0)

      Previous read of size 8 at 0x7ba000000080 by thread T16:
        #0 recv ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:6603 (libtsan.so.0+0x4f4a6)
        #1 net_recv_all ../app/src/util/net.c:228 (scrcpy+0x234a9)
        #2 stream_recv_packet ../app/src/stream.c:33 (scrcpy+0x2045c)
        #3 run_stream ../app/src/stream.c:228 (scrcpy+0x21169)
        #4 <null> <null> (libSDL2-2.0.so.0+0x905a0)

Refs ddb9396743
2022-01-27 23:26:46 +01:00
..
android Fix typos 2021-04-18 14:36:31 +02:00
sys Fix adb server hang 2021-12-11 19:09:11 +01:00
trait Add relative mode flag to mouse processors 2022-01-04 17:41:40 +01:00
util Avoid unused function warning 2022-01-01 23:27:34 +01:00
adb.c Fix return value on adb commands error 2022-01-27 16:47:51 +01:00
adb.h Add --tcpip feature 2021-11-29 20:39:03 +01:00
adb_parser.c Add function to find the device IP address 2021-11-29 20:39:03 +01:00
adb_parser.h Add function to find the device IP address 2021-11-29 20:39:03 +01:00
adb_tunnel.c Use flags for adb commands 2021-11-29 20:39:03 +01:00
adb_tunnel.h Extract adb tunnel to a separate component 2021-11-14 01:22:22 +01:00
aoa_hid.c Handle libusb_get_device_descriptor() error 2022-01-23 12:32:37 +01:00
aoa_hid.h Wait SET_CLIPBOARD ack before Ctrl+v via HID 2021-11-24 09:41:21 +01:00
cli.c Disable more actions if --no-control 2022-01-24 21:45:44 +01:00
cli.h Move scrcpy option structs to options.h 2021-10-27 18:43:47 +02:00
clock.c Improve slope estimation on start 2021-07-14 14:54:22 +02:00
clock.h Fix typo in clock comments 2021-10-29 12:21:34 +02:00
common.h Add CLAMP() macro 2022-01-04 17:41:40 +01:00
compat.c Add (v)asprintf compatibility functions 2021-11-24 19:55:00 +01:00
compat.h Require SDL >= 2.0.5 2021-12-06 23:49:55 +01:00
control_msg.c Use sc_ prefix for control_msg enums 2022-01-27 16:47:51 +01:00
control_msg.h Use sc_ prefix for control_msg enums 2022-01-27 16:47:51 +01:00
controller.c Use sc_ prefix for control_msg enums 2022-01-27 16:47:51 +01:00
controller.h Use sc_ prefix for control_msg 2022-01-14 22:17:30 +01:00
coords.h Use sc_ prefix for size, position and point 2021-10-30 15:20:39 +02:00
decoder.c Set "low delay" decoder flag 2021-12-08 23:53:54 +01:00
decoder.h Fix build with ffmpeg 5.0 2022-01-16 17:37:28 +01:00
device_msg.c Add OutOfMemory log helper 2021-11-24 22:06:49 +01:00
device_msg.h Add device clipboard set acknowledgement 2021-11-23 21:15:05 +01:00
events.h Run the server from a dedicated thread 2021-11-13 10:19:52 +01:00
file_pusher.c Rename file_handler to sc_file_pusher 2022-01-21 21:52:41 +01:00
file_pusher.h Rename file_handler to sc_file_pusher 2022-01-21 21:52:41 +01:00
fps_counter.c Rename scrcpy threads 2021-12-09 21:32:11 +01:00
fps_counter.h Wrap tick API 2021-07-14 14:22:32 +02:00
frame_buffer.c Fix code style 2022-01-27 19:02:07 +01:00
frame_buffer.h Extract current video_buffer to frame_buffer 2021-07-14 14:22:32 +02:00
hid_keyboard.c Make process_text() optional 2022-01-01 23:31:01 +01:00
hid_keyboard.h Synchronize HID keyboard state on first event 2021-10-26 21:30:04 +02:00
hid_mouse.c Fix warning message 2022-01-23 21:16:35 +01:00
hid_mouse.h Fix header guard prefix 2022-01-24 21:37:40 +01:00
icon.c Fix build with ffmpeg 5.0 2022-01-16 17:37:28 +01:00
icon.h Add icon loader 2021-10-25 18:08:37 +02:00
input_events.h Provide relative mouse motion vector in event 2022-01-04 17:41:40 +01:00
input_manager.c Use sc_ prefix for control_msg enums 2022-01-27 16:47:51 +01:00
input_manager.h Remove redundant control boolean 2022-01-23 12:16:24 +01:00
keyboard_inject.c Use sc_ prefix for control_msg enums 2022-01-27 16:47:51 +01:00
keyboard_inject.h Use sc_ prefix for controller 2022-01-14 22:17:30 +01:00
main.c Print version on stdout 2022-01-27 21:26:56 +01:00
mouse_inject.c Use sc_ prefix for control_msg enums 2022-01-27 16:47:51 +01:00
mouse_inject.h Use sc_ prefix for controller 2022-01-14 22:17:30 +01:00
opengl.c Enable trilinear filtering for OpenGL 2020-04-15 17:39:51 +02:00
opengl.h Define feature test macros in common.h 2021-01-17 14:08:48 +01:00
options.c Make auto-downsize on error optional 2022-01-21 18:36:46 +01:00
options.h Make auto-downsize on error optional 2022-01-21 18:36:46 +01:00
receiver.c Rename scrcpy threads 2021-12-09 21:32:11 +01:00
receiver.h Wait SET_CLIPBOARD ack before Ctrl+v via HID 2021-11-24 09:41:21 +01:00
recorder.c Rename scrcpy threads 2021-12-09 21:32:11 +01:00
recorder.h Use sc_ prefix for size, position and point 2021-10-30 15:20:39 +02:00
scrcpy.c Use sc_ prefix for control_msg enums 2022-01-27 16:47:51 +01:00
scrcpy.h Move scrcpy option structs to options.h 2021-10-27 18:43:47 +02:00
screen.c Capture mouse on start for --hid-mouse 2022-01-23 21:31:53 +01:00
screen.h Remove redundant control boolean 2022-01-23 12:16:24 +01:00
server.c Fix socket close race condition 2022-01-27 23:26:46 +01:00
server.h Make auto-downsize on error optional 2022-01-21 18:36:46 +01:00
stream.c Fix build with ffmpeg 5.0 2022-01-16 17:37:28 +01:00
stream.h Fix build with ffmpeg 5.0 2022-01-16 17:37:28 +01:00
v4l2_sink.c Rename scrcpy threads 2021-12-09 21:32:11 +01:00
v4l2_sink.h Fix build with ffmpeg 5.0 2022-01-16 17:37:28 +01:00
video_buffer.c Rename scrcpy threads 2021-12-09 21:32:11 +01:00
video_buffer.h Add buffering debugging tools 2021-07-14 14:54:22 +02:00