Bug/Quality: Protocol layer uses global I/O state; io_ssl is not thread-local #165
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
The protocol layer in
src/shared/protocol.cuses module-global state for the active connection:io_read_fd,io_write_fdarestatic __thread(thread-local), butio_sslis a plainstaticglobal. This means all threads in the same process share the sameSSL*object, which is not thread-safe. Although the server currently forks per TCP connection, the multithreaded server path (server.c:84-111) and the multithreaded client pipeline could race onio_ssl.Furthermore, the global state makes the protocol functions non-reentrant and harder to unit test.
Location
src/shared/protocol.c:13—static SSL* io_ssl = NULL;should bestatic __thread SSL* io_ssl = NULL;.src/shared/protocol.c:11-17— all I/O state is global.Suggested fix
io_sslthread-local, or better:send_n_data/receive_n_datato take an explicit I/O context struct (containing read fd, write fd, SSL pointer, and bandwidth limit) instead of using global state.Severity
Medium
Category
bug, quality
This issue was automatically generated by the issue-creator agent.