This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Socket module is not thread-safe
Type: Stage:
Components: Interpreter Core Versions:
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: loewis Nosy List: loewis, sobomax
Priority: high Keywords: patch

Created on 2006-08-21 23:24 by sobomax, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
socketmodule.diff.v2 sobomax, 2006-08-21 23:24 Proposed fix.
Messages (3)
msg50959 - (view) Author: Maxim Sobolev (sobomax) Date: 2006-08-21 23:24
The socket module make a great effort to be thread-
safe, but misses one 
big point - it uses single per-instance buffer to hold 
resolved 
sockaddr_xxx structures. Therefore, on SMP system it 
is possible that 
several threads calling functions that perform address 
resolution in 
parallel will stomp on each other resulting in 
incorrect or invalid address 
to be used in each case.

For example, two threads calling sendto() in parallel 
can result in packets 
to be sent to incorrect addresses - packets from 
thread one from time to 
time will be sent to address requested by thread two 
and vice versa.

Another, smaller issue is that the call to getnameinfo
() is not protected 
with netdb mutex on systems that don't have thread-
safe resolver.

P.S. This is very serious problem for us. For some 
reason my previous patch submission has been 
downgraded to bug report and forgotten completely, so 
that I am re-submitting.
msg50960 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2006-08-21 23:42
Logged In: YES 
user_id=21627

Sorry about forgetting your patch. Will look at it again for 2.5.1.

P.S. The previous issue was #1467080. It wasn't "downgraded to bug report"; 
instead, you submitted it as a bug report to start with.
msg50961 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2006-12-03 11:24
Thanks for the patch. Committed as r52906 and r52907.
History
Date User Action Args
2022-04-11 14:56:19adminsetgithub: 43870
2010-07-09 18:28:09skrahlinkissue1441984 superseder
2006-08-21 23:24:25sobomaxcreate