quality: server_host and server_port are mutable global variables (not thread-safe) #44

Closed
opened 2026-07-20 14:59:07 +02:00 by TapTap · 0 comments
Owner

In src/client/client_cli.c:14-15, two global variables are defined:

char* server_host = "127.0.0.1";
int server_port = 8080;

These globals are:

  1. Mutable (not const) -- they can be modified by --server-host and --server-port CLI args
  2. Shared across all threads -- both single-threaded and multithreaded send paths call into client_send.c which reads these globals
  3. Used in send_chunks_multithreaded (client_send.c:194,204) from the sender thread

This is not currently a data race because only the main thread modifies them before threads are created, but the design is fragile. Adding any feature that dynamically changes connection parameters could introduce threading bugs.

Better design: Pass server_host and server_port through the Config struct instead of using globals. The Config struct already exists and is passed through the pipeline context.

Severity: low

In src/client/client_cli.c:14-15, two global variables are defined: ```c char* server_host = "127.0.0.1"; int server_port = 8080; ``` These globals are: 1. Mutable (not const) -- they can be modified by --server-host and --server-port CLI args 2. Shared across all threads -- both single-threaded and multithreaded send paths call into client_send.c which reads these globals 3. Used in send_chunks_multithreaded (client_send.c:194,204) from the sender thread This is not currently a data race because only the main thread modifies them before threads are created, but the design is fragile. Adding any feature that dynamically changes connection parameters could introduce threading bugs. Better design: Pass server_host and server_port through the Config struct instead of using globals. The Config struct already exists and is passed through the pipeline context. Severity: low
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: TapTap/FastSync#44